Monday, November 20, 2017

PostgreSQL–Case insensitive search

By default when you use the LIKE operator in PostgreSQL, your query parameter is used in a case sensitive matter. This means that the query

SELECT * FROM “Products” WHERE “Name” LIKE ‘Beverag%’

will produce different results then

SELECT * FROM “Products” WHERE “Name” LIKE ‘beverag%’

A possible solution for this could be the use of regular expressions:

SELECT * FROM “Products” WHERE “Name” ~* 'beverag';
  

This query returns all matches where the name contains the word ‘beverag’ but because it is a case-insensitive search, it also matches things like ‘BEVERAGE’.

1 comment:

sunitha vishnu said...

Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
Android Training in Chennai
Ios Training in Chennai