From: | "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)postgresql(dot)org |
Subject: | BUG #1282: LIKE clause double-unescapes characters |
Date: | 2004-10-06 22:40:51 |
Message-ID: | 20041006224051.899295A32B4@www.postgresql.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
The following bug has been logged online:
Bug reference: 1282
Logged by: Justin Pasher
Email address: spam(at)pasher(dot)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 \'.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2004-10-06 22:53:54 | Re: BUG #1282: LIKE clause double-unescapes characters |
Previous Message | Sean Utt | 2004-10-06 21:54:40 | Re: Problem with interval |