BUG #1282: LIKE clause double-unescapes characters

Поиск
Список
Период
Сортировка
От PostgreSQL Bugs List
Тема BUG #1282: LIKE clause double-unescapes characters
Дата
Msg-id 20041006224051.899295A32B4@www.postgresql.com
обсуждение исходный текст
Ответы Re: BUG #1282: LIKE clause double-unescapes characters  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
The following bug has been logged online:

Bug reference:      1282
Logged by:          Justin Pasher

Email address:      spam@pasher.org

PostgreSQL version: 7.4.2

Operating system:   Debian Linux (unstable)

Description:        LIKE clause double-unescapes characters

Details:

Perhaps I'm missing something, but I didn't see an explanation for this
behavior in the docs (I also hope this wasn't fixed in a newer version of
Postgres, as 7.4.2 is the only one I have access to). It looks like the
Postgres query parser "double-unescapes" values for the LIKE clause, but not
the = clause. Here's my example:


justinp=# CREATE TABLE "test" (id serial, first_name varchar(50), last_name
varchar(50), primary key(id));
NOTICE:  CREATE TABLE will create implicit sequence "test_id_seq" for
"serial" column "test.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "test_pkey"
for table "test"
CREATE TABLE

justinp=# INSERT INTO "test" ("first_name", "last_name") VALUES
('Test\\''n', 'Test''n');
INSERT 26586973 1

justinp=# SELECT * FROM "test";
 id | first_name | last_name
----+------------+-----------
  1 | Test\'n    | Test'n
(1 row)

justinp=# SELECT * FROM "test" WHERE "first_name" = 'Test\\''n';
 id | first_name | last_name
----+------------+-----------
  1 | Test\'n    | Test'n
(1 row)

justinp=# SELECT * FROM "test" WHERE "first_name" LIKE 'Test\\''n';
 id | first_name | last_name
----+------------+-----------
(0 rows)

justinp=# SELECT * FROM "test" WHERE "last_name" LIKE 'Test\\''n';
 id | first_name | last_name
----+------------+-----------
  1 | Test\'n    | Test'n
(1 row)


From the results, you can see that the same query with the = converted into
a LIKE causes the value of the right hand side to be decoded twice, (making
"Test\\''n" turn into "Test\'n", then turn into "Test'n"). It happens this
way whether you escape the single quote as '' or as \'.

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Problem with interval
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #1282: LIKE clause double-unescapes characters