Escaping string for LIKE - Mailing list pgsql-general

From David Sheldon
Subject Escaping string for LIKE
Date
Msg-id 4CEBA649.4020202@we7.com
Whole thread Raw
Responses Re: Escaping string for LIKE  (Dmitriy Igrishin <dmitigr@gmail.com>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Matthew Walden
Date:
Subject: Re: postmaster.pid does not exist. cannot start postgres server on ubuntu
Next
From: Thom Brown
Date:
Subject: Re: Fwd: Postgres forums ... take 2