[英]How to get specific objects value from JSONB array in PostgreSQL?
I have a column named people
and it's type is JSONB .我有一个名为people
的列,它的类型是JSONB 。
Here is the sample data ( 1 row ):这是示例数据( 1 行):
{"addresses": [{"street":"cubuklu", "valid?": "true"}
{"street":"beykoz", "valid?":"false"}
{"street":"kavacik", "valid?": "true"} ]}
I would like to get list of streets that have valid?
我想获得valid?
街道的列表valid?
true value for all rows .所有行的真值。
Result:结果:
cubuklu
kavacik
......(data from other rows)
I'm able to list of arrays could not filter values tho.我能够列出无法过滤值的数组。
You need to unnest the array and then filter on the result:您需要取消嵌套数组,然后对结果进行过滤:
select adr.address ->> 'street'
from the_table t
cross join jsonb_array_elements(t.people -> 'addresses') as adr(address)
where adr.address ->> 'valid?' = 'true'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.