[英]postgres pull out multiple values in a JSON array
I have a table where one of the columns is a JSON array.我有一个表,其中一列是 JSON 数组。 for each key there are multiple values.每个键都有多个值。
So I use this query to select out the JSON所以我使用这个查询来选择 JSON
select x.cola eventid, x.colb
from special_event_conflicts t
cross join lateral json_each(t.eventid) as x(cola, colb)
which produces产生
"525947";"{"f1":133,"f2":2428,"f3":"MULTILINESTRING((1013339.30779158 180228.160778359,1013395.51179424 180119.844273224))"}"
what I want is to be able to select out the f1,f2,f3 values into there own columns我想要的是能够选择出 f1,f2,f3 值到那里自己的列
Click: demo:db<>fiddle 点击:demo:db<>fiddle
The most simple way is using the ->>
operator:最简单的方法是使用->>
运算符:
SELECT
x.event_id,
x.colb ->> 'f1' as f1,
x.colb ->> 'f2' as f2,
x.colb ->> 'f3' as f3
FROM <YOUR QUERY>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.