Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
postgres中的嵌套JSON查询_Json_Postgresql - Fatal编程技术网

postgres中的嵌套JSON查询

postgres中的嵌套JSON查询,json,postgresql,Json,Postgresql,我有以下几行JSON,不幸的是,其格式无法更改: { "elements": { "nodes": [ { "data": { "name": "Name here", "color": "#FFFFFF", "id": "n0" } } ] } } 这存储在postgres数据库中,我想通过上面JSON中嵌入的id提取记录。到目前为止,我已经尝试过这样

我有以下几行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';