PostGres LIKE

I always worked on mySQL, or as far back as I can remember, and usually when searching for a variable in a string you just do a LIKE, and it doesn’t worry about case(case insensitive).


SELECT user_id FROM tblUser WHERE first_name LIKE '%$searchVariable%'

BUT with PostGres the LIKE is case sensitive(aaarghhh).

In PostGres you would do something like this:

$variable = strtolower($variable);

// and then do the LIKE, the following way
SELECT user_id FROM tblUser WHERE lower(first_name) LIKE '%$searchVariable%'

Wish I could find a way just to make this step 1 line shorter…. maybe on of those cool PostGres custom function thingies….

Leave a Reply

Your email address will not be published. Required fields are marked *