Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.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
Sql 如何查询嵌套json/dict的项_Sql_Json_Postgresql_Jsonb - Fatal编程技术网

Sql 如何查询嵌套json/dict的项

Sql 如何查询嵌套json/dict的项,sql,json,postgresql,jsonb,Sql,Json,Postgresql,Jsonb,我的表是contacts\u contact,而该列称为fields 就上下文而言,我感兴趣的json的第一部分表示一个流ID和来自用户的相应响应 像这样::{“text”,“false”} 其中text是my字段的数据类型,false表示用户不同意。他们也可以选择真实和同意 在伪代码中,以下是我要做的: 搜索联系人\u联系人 返回键为6784cbd4-505d-4ee4-8568-fb69913d6998的所有行 和回复(值)为假。(表示“文本”为“假”) 换言之,应选择字段列中包含“”678

我的表是contacts\u contact,而该列称为fields

就上下文而言,我感兴趣的json的第一部分表示一个流ID和来自用户的相应响应

像这样:
:{“text”,“false”}

其中text是my字段的数据类型,false表示用户不同意。他们也可以选择真实和同意

在伪代码中,以下是我要做的:

  • 搜索联系人\u联系人
  • 返回键为
    6784cbd4-505d-4ee4-8568-fb69913d6998的所有行
    回复(值)为假。(表示“文本”为“假”)
  • 换言之,应选择字段列中包含“
    ”6784cbd4-505d-4ee4-8568-fb69913d6998:“{”text:“false”}
    ”的每一行

    下面是字段列下的示例数据。第一部分是我感兴趣的检索内容

    {
      "6784cbd4-505d-4ee4-8568-fb69913d6998": {"text": "false"},
      "70454b00-f408-4e69-8013-b010c3130fdd": {"text": "2020-05-04",
      "datetime": "2020-05-04T09:38:42.329388+02:00"},
      "9fc9e443-4bbb-4356-b9cc-71a6c15ded0e": {"text": "<1 month"},
      "abb3bb06-d4b7-4a58-8a3f-b100074b20a2": {"text": "<1 month"},
      "b55eb0e6-af0d-48c7-b2eb-f46529bdd07b": {"text": "True"},
      "b692354b-f314-406a-8ed8-47b7dde34379": {"text": "true"},
      "c7d75b60-f1d8-4588-affa-4ef148c75873": {"text": "WhatsApp"},
      "c80e14a9-e10f-41c8-ae59-c0ca14abf806": {"text": "true"},
      "cbfd64b8-739c-4913-b8c9-ba366043f1bd": {"text":
      "2020-04-20T00:00:00.000000+02:00", "datetime":
      "2020-04-20T00:00:00.000000+02:00"},
      "d5423a09-5486-4b80-bcae-4fc1e11b0dfa": {"text": "true"},
      "db36481d-3bb2-435d-b63d-bc9d5b5eadd3": {"text": "TRUE"},
      "e0f301ab-56eb-4bba-a6c1-d9668033172f": {"text": "Late Adopter"}
    }
    
    {
    “6784cbd4-505d-4ee4-8568-fb69913d6998”:{“文本”:“假”},
    “70454b00-f408-4e69-8013-b010c3130fdd”:{“文本”:“2020-05-04”,
    “日期时间”:“2020-05-04T09:38:42.329388+02:00”,
    
    “9fc9e443-4bbb-4356-b9cc-71a6c15ded0e:{“文本”:“这可以使用contains运算符
    @>

    select *
    from contacts_contact
    where fields @> '{"6784cbd4-505d-4ee4-8568-fb69913d6998" : {"text": "false"}}';
    
    上面假设
    fields
    jsonb
    列(应该是)。如果不是,则需要强制转换它:
    fields::jsonb