Thread: BUG #1454: error in "select * from table where a1 like '%\%%' " ???

BUG #1454: error in "select * from table where a1 like '%\%%' " ???

From
"Ricky"
Date:
The following bug has been logged online:

Bug reference:      1454
Logged by:          Ricky
Email address:      ricky@ez2.us
PostgreSQL version: 8.0
Operating system:   Mandrake Linux 10.1
Description:        error in "select * from table where a1 like '%\%%' " ???
Details:

I perform a query to get data,which contains '%'.
so I do this query.
select * from table where a1 like '%\%%';
but it returns all rows.
then I do another query.
select * from table where a1 like '\%';
but it still return all rows.
like "select * from table"

Re: BUG #1454: error in "select * from table where a1 like '%\%%' " ???

From
Peter Eisentraut
Date:
Ricky wrote:
> I perform a query to get data,which contains '%'.
> so I do this query.
> select * from table where a1 like '%\%%';
> but it returns all rows.

select * from table where a1 like '%\\%%';

The first \ escapes the second \ for the string parser, the second \ is
the escape character for the LIKE pattern.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/