我在以下几行中有一些JSON,不幸的是,其格式无法更改:
{
"elements": {
"nodes": [
{
"data": {
"name": "Name here",
"color": "#FFFFFF",
"id": "n0"
}
}
]
}
}
这存储在postgres数据库中,我想通过上面JSON中嵌入的id提取记录。到目前为止,我已经尝试过这样的事情:
SELECT "data".* FROM "data" WHERE payload #>> '{elements,nodes,data,id}' = 'n0';
...没有成功; 尽管此查询运行,但不返回任何内容。任何人都可以建议如何做到这一点吗?
创建架构:
create table json (
id serial primary key,
data jsonb
);
insert into json (data) values (
'{ "elements": {
"nodes": [
{
"data": {
"name": "Name here",
"color": "#FFFFFF",
"id": "n0"
}
}
]
}
}
'::jsonb);
查询本身:
select * from json js,jsonb_array_elements(data->'elements'->'nodes') as node
where node->'data'->>'id' = 'n0';
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句