pgsql (PostgresSQL) 查询的时候忽略大小写

Posted 石头StoneWang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pgsql (PostgresSQL) 查询的时候忽略大小写相关的知识,希望对你有一定的参考价值。

背景

  • 有时候我们不能忽略大小写,如密码的比对 (这一般也在Java中对比,不存在SQL中进行区分的需求)
  • 搜索的时候忽略大小写

如何忽略大小写

pgsql/ postgresql 如何查询的时候忽略大小写?

假设有 fock5 的数据

  • select * from data_group where name=‘fuck5’; --能查出

  • select * from data_group where name=‘Fuck5’; --不能

  • select * from data_group where lower(name)=lower(‘Fuck5’); --能查出

    是解决方案之一,只是用不上索引了

  • select * from data_group where name ilike ‘Fuck5’; --能查出

    ilike跟like一样只是忽略大小写,这也是解决方法之一,是变通的方案,因为like(ilike)不使用%就相当于=

  • select * from data_group where name like ‘%fuck%’; --能查出

  • select * from data_group where name like ‘%Fuck%’; --不能

  • select * from data_group where name ilike ‘%Fuck%’; --能查出

以上是关于pgsql (PostgresSQL) 查询的时候忽略大小写的主要内容,如果未能解决你的问题,请参考以下文章

PostgresSQL查询数据中用逗号隔开的数据以及@>与<@的区别

PostgresSQL调优实践:分区表不能统计下推的排查

PostgresSQL调优实践:分区表不能统计下推的排查

提高 PostgresSQL 聚合查询性能

sql PostgresSQL查询显示给定用户具有特定类型权限的表

pgsql中json格式数组查询结果变成了字符串