Re: LIKE predicate and '\' character

From: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
To: Andy Hallam <ahm(at)exel(dot)co(dot)uk>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: LIKE predicate and '\' character
Date: 2001-11-07 14:11:11
Message-ID: 20011107151110.C6354@zf.jcu.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 07, 2001 at 12:56:46PM -0000, Andy Hallam wrote:

The PostgreSQL parser "eat" one '\' on arbitrary place in query. You
you want put '\' to some function (operator) you must use '\\'.

test=# select '\\';
?column?
----------
\
(1 row)

test=# select '\\\\';
?column?
----------
\\
(1 row)

test=# select 'hello\\pg' like 'hello\\pg';
?column?
----------
f
(1 row)

test=# select 'hello\\pg' like 'hello\\\\pg';
?column?
----------
t
(1 row)

Karel

> PostgreSQL - 7.1.3 (installed on Linux 2.4.2-2)
> PSQLODBC.DLL - 07.01.0007
> Visual C++ - 6.0
>
> I sent a previous mail with regard to using the '\' (backslash) character in
> an SQL SELECT statement.
> The outcome was that postgres does not escape the '\' itself - I need to do
> it myself before submitting the SQL - fair enough, I now do this.
>
> i.e
> instead of
> mydb=# SELECT * FROM users WHERE id = 'WORKGROUP\me';
> I now do
> mydb=# SELECT * FROM users WHERE id = 'WORKGROUP\\me';
>
> BUT, if I use the LIKE predicate I have to escape the escape.
>
> i.e
> mydb=# SELECT * FROM users WHERE id LIKE 'WORKGROUP\\\\me';
>
>
> Now this must be treated as a bug.
> As you can see it is not an error with the PSQLODBC driver as I ran the SQL
> from the command line with the same results.
> I am presuming that the backend parsing logic around the LIKE prodicate is
> ignoring the '\'.
>
> Is anyone working on this ?. Can anyone send me a fix, as without this I'm
> screwed.
>
> Thanks for any help
>
> Andy.
> ahm(at)exel(dot)co(dot)uk
>
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

--
Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
http://home.zf.jcu.cz/~zakkr/

C, PostgreSQL, PHP, WWW, http://docs.linux.cz, http://mape.jcu.cz

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2001-11-07 15:15:46 Re: GSL (GNU Scientific library, numerical routines) interface
Previous Message Roberto Mello 2001-11-07 13:57:45 Re: Porting Web application written in Oracle 8 PL/SQL to Postgresql