gpt4 book ai didi

Postgresql 在 jsonb 对象中搜索值

转载 作者:行者123 更新时间:2023-12-03 08:48:20 26 4
gpt4 key购买 nike

我的表中有一个 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**********') ;

最佳答案

? 查找顶级 key 。您显示的 JSON 仅具有两个顶级键:“消息”和“元数据”。所以它们当然不匹配“91************”。

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

 @> '{"message":{"recipient":{"to":"91**********"}}}'

列上的任一类型的 JSONB GIN 索引都将支持此功能。

关于Postgresql 在 jsonb 对象中搜索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60483978/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com