[英]Get element from array of JSON postgres
I have a column x with data type jsonb
我有一个数据类型为
jsonb
的列x
and the value looks like: 值看起来像:
[
[{"string":"whateverstring1"}],
[{"string":"whateverstring2"}]
]
How to return each element of the array? 如何返回数组的每个元素?
Something like this: " whateverstring1 "," whateverstring2 " 像这样的东西:“ whatthingstring1 ”,“ whatthingstring2 ”
SELECT jsonb_array_elements(jsonb) -> 0 -> 'string'
FROM (
SELECT '[[{"string":"whateverstring1"}],[{"string":"whateverstring2"}]]'::jsonb
) s
jsonb_array_elements
extract each element into one row jsonb_array_elements
每个元素提取到一行 -> 0
gives the first element of the nested arrays which is {"string":"whateverstring1"}
-> 0
给出嵌套数组的第一个元素,即{"string":"whateverstring1"}
-> 'string'
gives the value of the elements -> 'string'
给出元素的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.