问题描述
我看过类似的问题,但找不到如何将字典存储在以下位置:
表A: id int,数据jsonb
For example:
id = 1
data = {"Key1": 1,"Key2": "a2","Key3": [3,4]}
到表B: id int,键文本,有效载荷jsonb
Using the same example as above,I would get the 3 records:
id Key payload
--------------------
1 Key1 1
1 Key2 "a2"
1 Key3 [3,4]
在此先感谢您的帮助!
解决方法
使用jsonb_each()
:
insert into table_b
select id,key,payload
from table_a
cross join lateral jsonb_each(data) as e(key,payload);