将jsonb转换为所需的表类型存在问题,我们将不胜感激。
我的jsonb是:
{"left": ["ICMB", "IPERIOD", "IADDR", "KV"]}
我想要将其转换为:
position element
left ICMB
left IPERIOD
left IADDR
left KV
提前致谢!
答案 0 :(得分:0)
使用jsonb_each()
and jsonb_array_elements_text()
:
with my_data(j) as (
values
('{"left": ["ICMB", "IPERIOD", "IADDR", "KV"]}'::jsonb)
)
select key as position, element
from my_data,
lateral jsonb_each(j) as each(key, val),
lateral jsonb_array_elements_text(j->key) as element;
position | element
----------+---------
left | ICMB
left | IPERIOD
left | IADDR
left | KV
(4 rows)