我在检查表中的jsonb列为空时遇到了问题。
当我的列directions为空时,它的值为"{}"
尝试了以下方法:
Model.where("directions != '{}'") <- brings all
Model.where("directions <@ '{}'") <- brings all
我是否还有其他不知道的方法?使用PostgreSQL 9.6
我在检查表中的jsonb列为空时遇到了问题。
当我的列directions为空时,它的值为"{}"
尝试了以下方法:
Model.where("directions != '{}'") <- brings all
Model.where("directions <@ '{}'") <- brings all
我是否还有其他不知道的方法?使用PostgreSQL 9.6
Model.where.not(directions: '{}')
ERROR: operator does not exist: json <> unknown
- phil pirozhkovModel.where.not("directions::text = ?", "{}")
.not
来否定查询:Model.where.not("directions = '{}'")
Model.where("directions != '{}'")
可以工作,但Model.where.not(directions: '{}')
更符合 Rails 的风格(但等效)。如果这些查询返回了所有数据,那么您确定有任何实例包含实际的方向数据吗? - FrostModel.where.not(directions: '{}')
。回答你的问题,是的,我有大小写记录。 - Petros Kyriakou