PostgreSQL在JSONB阵列上加入
我是JSONB的新手,我想知道,如果有一个查询可以使用以下内容:
我有很多看起来像这样的桌子:
ID (INT) | members (JSONB)
所有桌子只有一行。
2个表的示例
table1 :
id :1
data :
[
{
"computer": "12.12.12.12",
"tag": "dog"
},
{
"computer": "1.1.1.1",
"tag": "cat"
},
{
"computer": "2.2.2.2",
"tag": "cow"
}
]
table2 :
id : 1
data :
[
{
"IP address": "12.12.12.12",
"name": "Beni",
"address": "Rome"
},
{
"IP address": "1.1.1.1",
"name": "Jone",
"address": "Madrid"
}
]
结果应该是这样的行:
计算机 | 标签 | 名称 |
---|---|---|
12.12.12.12 | 狗 | 贝尼 |
1.1.1.1 | 猫 | jone |
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用然后加入它们(就像它们是关系表一样)。
Convert jsons into
setof
types using jsonb_to_recordset function and then join them (like they were relational tables).db fiddle
要从jsonb阵列中获取值,您必须以某种方式爆炸它们。
JSONB_ARRAY_ELEMENTS的另一种方法:
to get values out of a jsonb array of objects you somehow have to explode them.
another way with jsonb_array_elements:
https://www.db-fiddle.com/f/68iC5TzLKbzkLZ8gFWYiLz/0