json - 在 PostgreSQL 12 中提取 JsonB 字典的元素
问题描述
我看过类似的问题,但我找不到如何将字典存储在:
表A:id int,数据jsonb
For example:
id = 1
data = {"Key1": 1, "Key2": "a2", "Key3": [3, 4]}
到表 B:id int、key text、payload 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);
推荐阅读
- c# - SolidWorks PDM 插件访问文件
- css - ReactJS 7 - 如何根据其值有条件地仅更改表格单元格(而不是行)的背景颜色?
- linux - Debian 10 - qt.qpa.plugin:无法在“”中加载 Qt 平台插件“xcb”,即使它被发现
- eclipse - Eclipse 市场无法加载
- python-3.x - 删除字符串中的特殊字符 - python 3
- java - listView 不能动态更新
- sql - Postgres JSONB 选择 json 对象作为列
- python - 如何在 Python 的 GUI 中打印字典中的所有值
- node.js - 在 nodeJS 中找到请求将被重定向到的最终 URL?
- php - 对php导航感到困惑