Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.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
获取JSONB列POSTGRESQL中的嵌套值_Postgresql_Jsonb - Fatal编程技术网

获取JSONB列POSTGRESQL中的嵌套值

获取JSONB列POSTGRESQL中的嵌套值,postgresql,jsonb,Postgresql,Jsonb,我有一个带有jsonb列的表guest\u group。我想查询一个ID,其中ID\u Context等于protelIO 以下是表格的列: [ { "protelSurname":"Smith", "servicio_tags":[ "protel-info" ], "protelUniqueID":"[{\"ID\":\"294623726\",\"Type\":\"21\",\"ID_Context\":\"GHA\"

我有一个带有jsonb列的表
guest\u group
。我想查询一个ID,其中
ID\u Context
等于
protelIO

以下是表格的列:

[
   {
      "protelSurname":"Smith",
      "servicio_tags":[
         "protel-info"
      ],
      "protelUniqueID":"[{\"ID\":\"294623726\",\"Type\":\"21\",\"ID_Context\":\"GHA\"},{\"ID\":\"4842148\",\"Type\":\"1\",\"ID_Context\":\"protelIO\"}]",
      "protelGivenName":"Seth"
   },
   {
      "value":"test",
      "display_name":"Traces",
      "servicio_tags":[
         "trace"
      ]
   }
]
我的尝试:

SELECT field ->>'protelUniqueID' 
FROM guest_group gg
 cross join lateral  
jsonb_array_elements(custom_fields) AS field
 
WHERE value @> '{"servicio_tags": ["protel-info"]}'::jsonb

这给了我:

[{“ID”:“294623726”,“Type”:“21”,“ID_上下文”:“GHA”},{“ID”:“4842148”,“Type”:“1”,“ID_上下文”:“protelIO”}]

我如何才能走完最后一英里,只获得带有值密钥对的
ID
密钥的值
“ID\u Context”:“protelIO”


我感谢你的帮助

我想这会让你得到想要的结果。可能不太漂亮:-)

select * from (select jsonb_array_elements(f) from (
    select (field ->>'protelUniqueID')::jsonb f
    FROM guest_group gg,
    lateral jsonb_array_elements(custom_fields) AS field
    WHERE value @> '{"servicio_tags": ["protel-info"]}'::jsonb
) d(f)) dd(x) 
where x->>'ID_Context'='protelIO';