Thread: Select with backslash '\' character

Select with backslash '\' character

From
"Andy Hallam"
Date:
PostgreSQL - 7.1.3  (installed on Linux 2.4.2-2)
PSQLODBC.DLL - 07.01.0007
Visual C++ - 6.0

SELECT a FROM b WHERE c = 'WORKGROUP\me'

Does not return any rows.

SELECT a FROM b WHERE c = 'WORKGROUP\\me'

Returns required rows.

Result = PostgreSQL ODBC driver cannot handle backslash character - have to
escape it myself.

Can someone confirm this to be a bug please.

Thanks.

Andy
ahm@exel.co.uk

Re: Select with backslash '\' character

From
"Andy Hallam"
Date:
Just to clarify.

---
The below SELECT SQL was ran from the command line:

mydb=# SELECT a FROM b WHERE c = 'WORKGROUP\me'
Result = Zero rows returned.

mydb=# SELECT a FROM b WHERE c = 'WORKGROUP\\me'
Result = One row returned.

---
And from my C app.

strcpy(strID, "WORKGROUP\\me");
Result = Zero rows returned.

strcpy(strID, "WORKGROUP\\\\me");
Result = One row returned.


"Andy Hallam" <ahm@exel.co.uk> wrote in message
news:9rc03b$16df$1@news.tht.net...
> PostgreSQL - 7.1.3  (installed on Linux 2.4.2-2)
> PSQLODBC.DLL - 07.01.0007
> Visual C++ - 6.0
>
> SELECT a FROM b WHERE c = 'WORKGROUP\me'
>
> Does not return any rows.
>
> SELECT a FROM b WHERE c = 'WORKGROUP\\me'
>
> Returns required rows.
>
> Result = PostgreSQL ODBC driver cannot handle backslash character - have
to
> escape it myself.
>
> Can someone confirm this to be a bug please.
>
> Thanks.
>
> Andy
> ahm@exel.co.uk
>
>
>

Re: Select with backslash '\' character

From
Tom Lane
Date:
"Andy Hallam" <ahm@exel.co.uk> writes:
> SELECT a FROM b WHERE c = 'WORKGROUP\me'
> Does not return any rows.
> SELECT a FROM b WHERE c = 'WORKGROUP\\me'
> Returns required rows.

> Can someone confirm this to be a bug please.

This is not a bug.  Backslash is an escape character in Postgres'
string literals, therefore you gotta double it to get a single
backslash into the actual data.

            regards, tom lane

Re: Select with backslash '\' character

From
Stephan Szabo
Date:
On Fri, 26 Oct 2001, Andy Hallam wrote:

> PostgreSQL - 7.1.3  (installed on Linux 2.4.2-2)
> PSQLODBC.DLL - 07.01.0007
> Visual C++ - 6.0
>
> SELECT a FROM b WHERE c = 'WORKGROUP\me'
>
> Does not return any rows.
>
> SELECT a FROM b WHERE c = 'WORKGROUP\\me'
>
> Returns required rows.
>
> Result = PostgreSQL ODBC driver cannot handle backslash character - have to
> escape it myself.

Actually, it's probably the backend since I'm pretty sure you get the
same thing in psql.  IIRC, the \ is treated as an escape character to
escape what follows (like a ' or for providing octal values).