Postgresql case-insensitive queries

postgresql provides powerful regular expression system that can achieve fuzzy query at the database level.

Match Regular Expression Operators:

Operators description example
~ Match the regular expression, case sensitive 'Thomas' ~ '. * Thomas *.'
~* Match the regular expression, case insensitive 'Thomas' ~ *. * Thomas. *'
!~ Does not match regular expression, case sensitive 'Thomas'! ~ '. * Thomas. *'
!~* Does not match regular expression, case insensitive 'thomas' !~* '.*vadim.*'


For example:

to find the data sheet account all user names containing information about the user baidu not case-sensitive.

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

the use of regular expressions may be implemented after the case-insensitive function, and greatly reduces the length of the sql statement.

Guess you like

Origin www.cnblogs.com/fanrenren/p/11582402.html