Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.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
Postgresql在jsonb对象中搜索值_Postgresql_Jsonb - Fatal编程技术网

Postgresql在jsonb对象中搜索值

Postgresql在jsonb对象中搜索值,postgresql,jsonb,Postgresql,Jsonb,我在一个表中有一个jsonb字段,其值为 { "message": { "sender": { "from": "91**********" }, "channel": "some kind of text", "content": { "text": "some kind of text", "type": "text" }, "recipient": { "to": "91******

我在一个表中有一个jsonb字段,其值为

    {
  "message": {
    "sender": {
      "from": "91**********"
    },
    "channel": "some kind of text",
    "content": {
      "text": "some kind of text",
      "type": "text"
    },
    "recipient": {
      "to": "91**********",
      "recipient_type": "some kind of text"
    },
    "preferences": {
      "webHookDNId": "some kind of text"
    }
  },
  "metaData": {
    "version": "some kind of text"
  }
}
现在我想搜索对象的“to”键中具有特定电话号码的所有此类值。我正在为此使用以下查询,但它不起作用

select * from table_name where (column1::jsonb ? '91**********') ;

您可以使用
->
->
从键中提取值:

select *
from the_table
where (the_column -> 'recipient' ->> 'to') = '91**********';
#>
运算符

select *
from the_table
where the_column #>> '{recipient,to}' = '91**********';

查找顶级密钥。您显示的JSON只有两个顶级键,“message”和“metadata”。当然,它们与“91*********”不匹配

您可能需要包含运算符
@>

 @> '{"message":{"recipient":{"to":"91**********"}}}'
这将由列上的任一类型的JSONB GIN索引支持