Re: BUG #2729: Backslash escaping not working as expected

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Michael van Rooyen" <mvanr(at)bigfoot(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2729: Backslash escaping not working as expected
Date: 2006-11-02 16:57:11
Message-ID: 17770.1162486631@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Michael van Rooyen" <mvanr(at)bigfoot(dot)com> writes:
> The following query from psql:
> select * from product where name like '%\\%';
> Yields products whose names end with a %. I would have expected it to yeild
> products whose names contained a backslash.

Postgres defaults to assuming \ as the LIKE escape character, that is,
what you typed is equivalent to

select * from product where name like '%\\%' escape '\\';

You can get the behavior you're expecting by not having any escape character:

select * from product where name like '%\\%' escape '';

This is as explained in TFM:
http://www.postgresql.org/docs/8.1/static/functions-matching.html#FUNCTIONS-LIKE
although I notice that SQL92 says that there is no escape character by
default. We can't change our historical documented behavior on the
point unless we were willing to provide a configuration variable to
adjust it, and I'm not sure it's worth that.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2006-11-02 17:00:33 Re: BUG #2730: strange query performance !
Previous Message Tom Lane 2006-11-02 16:35:43 Re: documentation