I am trying to retrieve the contact names based on the keyed search string. It performs good for the English alphabets and behaves strangely for special chars such as _,/,\,%
My query in the function is similar to
SELECT contact_name FROM contacts WHERE LOWER(contact_name) LIKE LOWER('_McDonald%') ORDER BY LOWER(contact_name) ASC LIMIT 1;
It looks like, during searching, it retrieves all the contact names instead of the desired. The similar bizarre happens for the above mentioned special chars. I need to support these. How do I educate postgres to consider these chars? Please guide me.
Thanks and Regards,
Siva.
Just to complete the picture:
You can also use the ESCAPE clause to specify the character for escaping the wildcards. This is useful if you’d like to include e.g. a
\in your search string.Btw: I would recommend to turn on the configuration option
standard_conforming_stringsto avoid confusion (Haes’ answer avoids this problem by using theE'syntax).Since 9.1 this is the default mode anyway.