如何检查jsonb列是否为空Postgres

时间:2016-11-04 12:07:37

标签: ruby-on-rails postgresql

我无法检查表格的jsonb列何时为空。

我的专栏路线为空时的值为“{}”

尝试以下

Model.where("directions != '{}'") <- brings all
Model.where("directions <@ '{}'") <- brings all

还有其他我不知道的方式吗?使用postgresql 9.6

3 个答案:

答案 0 :(得分:2)

Model.where.not(directions: '{}')

答案 1 :(得分:0)

Model.where.not("directions::text = ?", "{}")

答案 2 :(得分:-2)

尝试使用.not否定查询:

Model.where.not("directions = '{}'")
相关问题