如何正确实现jsonb数组的位置?

问题描述 投票:0回答:1

我添加了要在其中存储ID的jsonb字段。

接下来,我需要通过该字段的内容对记录进行“搜索”。

[在所有地方,包括文档(link),我都看到了此运算符-@>。但我没有设法使用它:

User.where.not("migration_ids @> ?", 1)
ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR:  operator does not exist: jsonb @> integer)
LINE 1: ...s".* FROM "users" WHERE NOT (migration_ids @> 1) LIMI...
                                                      ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

请告诉我,如何正确处理?

ruby-on-rails activerecord ruby-on-rails-5 ruby-on-rails-6
1个回答
1
投票

这应该有效User.where.not("migration_ids @> ?", "1")

© www.soinside.com 2019 - 2024. All rights reserved.