Postgresql查询时不区分大小写

postgresql提供有强大的正则表达式系统,可以在数据库级别实现模糊查询。

正则表达式匹配操作符:

操作符 描述 例子
~ 匹配正则表达式,大小写相关 'thomas' ~ '.*thomas.*'
~* 匹配正则表达式,大小写无关 'thomas' ~* '.*Thomas.*'
!~ 不匹配正则表达式,大小写相关 'thomas' !~ '.*Thomas.*'
!~* 不匹配正则表达式,大小写无关 'thomas' !~* '.*vadim.*'


例如:

找出数据表account中所有用户名包含baidu且不区分大小写的用户的信息。

select * from account where username ~* 'baidu';

使用正则表达式之后可以实现不区分大小写的功能,并且大大减少了sql语句的长度。

猜你喜欢

转载自www.cnblogs.com/fanrenren/p/11582402.html