[英]How to find the key for the minimum value in jsonb column of postgres?
[英]How to find key of hash in jsonb in Rails?
樣板房示例,列:動物。 里面的動物 jsonb 是這樣的:
dogs: {
dog1: { attributes...},
dog2: { attributes...},
...
}
題
如何僅通過鍵(“dog1”)找到 dog1
Active Record 本身不支持這一點。 您必須編寫一些自定義 where 子句。 例如在 Postgres 中,請參閱此處的文檔: https : //www.postgresql.org/docs/9.4/functions-json.html 。
此處列出了一些示例: https ://nandovieira.com/using-postgresql-and-jsonb-with-ruby-on-rails,在“查詢您的 jsonb 列”部分下!
# preferences->twitter OR preferences->github
User.where('preferences ?| array[:keys]', keys: ['twitter', 'github'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.