简体   繁体   English

Rails PSQL JSON查询:在未知位置找到嵌套的数组元素?

[英]Rails PSQL JSON query: find the nested array element at unknown position?

Please see an example here: http://edgeguides.rubyonrails.org/active_record_postgresql.html#json 请在此处查看示例: http : //edgeguides.rubyonrails.org/active_record_postgresql.html#json

How do I get all the records containing "jack" inside change array? 如何获取change数组中包含"jack"所有记录?

I can currently do it with such a query: 我目前可以用这样的查询来做到这一点:

Event.where("payload #>> '{change,0}' = 'jack' ")

But what if I don't know the exact "jack" 's position (0 in this case) inside change array? 但是,如果我不知道change数组中确切的"jack"位置(在这种情况下为0)怎么办? How to rearrange the Rails PSQL query then? 那么如何重新排列Rails PSQL查询呢?

看一下JSON类型内的查询数组元素 ,特别是@> (包含)运算符的讨论(如果使用的是jsonb列)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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