PostgreSQL:如何进行“不区分大小写”查询

本文介绍了在PostgreSQL中进行不区分大小写查询的方法,包括使用`ILIKE`,`lower()`或`upper()`函数,以及POSIX正则表达式。讨论了这些方法的性能和适用场景,并提供了相关链接以获取更多信息。
摘要由CSDN通过智能技术生成

本文翻译自:PostgreSQL: How to make “case-insensitive” query

Is there any way to write case-insensitive queries in PostgreSQL, Eg I want that following 3 queries return same result. 有什么办法可以在PostgreSQL中编写不区分大小写的查询,例如,我希望以下3个查询返回相同的结果。

SELECT id FROM groups where name='administrator'

SELECT id FROM groups where name='ADMINISTRATOR'

SELECT id FROM groups where name='Administrator'

#1楼

参考:https://stackoom.com/question/tooK/PostgreSQL-如何进行-不区分大小写-查询


#2楼

You can also read up on the ILIKE keyword. 您也可以阅读ILIKE关键字。 It can be quite useful at times, albeit it does not conform to the SQL standard. 尽管它不符合SQL标准,但有时可能会非常有用。 See here for more information: http://www.postgresql.org/docs/9.2/static/functions-matching.html 请参阅此处以获取更多信息: http : //www.postgresql.org/docs/9.2/static/functions-matching.html


#3楼

You can use ILIKE . 您可以使用ILIKE ie

SELECT id FROM groups where name ILIKE 'administrator'

#4楼

使用ILIKE代替LIKE

SELECT id FROM groups WHERE name ILIKE 'Administrator'

#5楼

You could also use POSIX regular expressions, like 您还可以使用POSIX正则表达式,例如

SELECT id FROM groups where name ~* 'administrator'

SELECT 'asd' ~* 'AsD' returns t SELECT 'asd' ~* 'AsD'返回t


#6楼

Using ~* can improve greatly on performance, with functionality of INSTR. 使用~*可以通过INSTR的功能极大地提高性能。

SELECT id FROM groups WHERE name ~* 'adm'

return rows with name that contains OR equals to 'adm'. 返回名称包含OR的行等于“ adm”。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值