简体   繁体   中英

Rails: How to check if jsonb column is empty Postgres

I am having trouble checking when the jsonb column of my table is empty.

My column directions when empty has value "{}"

Tried the following

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

is there any other way that i am not aware of? Using postgresql 9.6

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

尝试使用.not否定查询:

Model.where.not("directions = '{}'")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM