gpt4 book ai didi

sql - 如何在 postgresql jsonb 搜索中使用 SIMILAR TO 子句获取不区分大小写的数据?

转载 作者:行者123 更新时间:2023-11-29 14:25:10 32 4
gpt4 key购买 nike

下面是我用来获取数据的查询。它正在提供数据。但我想使用 DxC 到 sercah,所以它应该提供所有与 dxc 相关的数据。

当前查询:

select count(*) 
from enterprise_1.contacts_master
where contact_data::json->>'Company' SIMILAR TO ('%(DXC|dxc)%')

对/对:2

预期查询

select count(*) 
from enterprise_1.contacts_master
where contact_data::json->>'Company' SIMILAR TO ('%(DxC)%')

当前输出:0
预期 o/p:2

我不想使用ILike

最佳答案

如果你想以不区分大小写的方式进行搜索,那么

where contact_data::json->>'Company' ILIKE '%DxC%'

正是您要寻找的。

由于 ILIKE 不区分大小写,因此无需提供不同版本的子字符串。以上将匹配公司字符串中任何位置的 dxcDXCdXcDxc

如果你想使用(不区分大小写的)正则表达式,你可以使用 ~* operator

where contact_data::json->>'Company' ~* 'DxC'

~* 以不区分大小写的方式基于正则表达式进行比较。以上搜索忽略大写/小写的公司字符串中任意位置的子字符串 'DxC'

关于sql - 如何在 postgresql jsonb 搜索中使用 SIMILAR TO 子句获取不区分大小写的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58619760/

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