Re: Escaping string for LIKE

Поиск
Список
Период
Сортировка
От Dmitriy Igrishin
Тема Re: Escaping string for LIKE
Дата
Msg-id AANLkTikkXgNnghPPGE5B53LKXRzY0-2ny6SsTguaukW6@mail.gmail.com
обсуждение исходный текст
Ответ на Escaping string for LIKE  (David Sheldon <david@we7.com>)
Список pgsql-general
Hey David,

I guess, that you should escape, like this

dmitigr=> SELECT regexp_replace('di_ma%', '(%|_)', E'\\\\\\1', 'g');
 regexp_replace
----------------
 di\_ma\%


2010/11/23 David Sheldon <david@we7.com>
If I have a string, and I want to search for everything that starts with that string then I could do:

SELECT * FROM users WHERE name LIKE string || '%';

Now, if string contains \, _ or % then it won't do what I expect.

Is there a built-in function that I can call to escape the string so that it isn't special for LIKE, or is it a case of regexing and putting a \ before each \, _ or %?

David

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



--
// Dmitriy.


В списке pgsql-general по дате отправления:

Предыдущее
От: akp geek
Дата:
Сообщение: Re: Problem with replace function in postgres
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: Problem with replace function in postgres