Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] escape character \

From: "Jose' Soares Da Silva" <sferac(at)proxy(dot)bazzanese(dot)com>
To: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql/questions(at)postgreSQL(dot)org, pgsql-hackers(at)postgreSQL(dot)org, sferac(at)bo(dot)nettuno(dot)it
Subject: Re: [HACKERS] escape character \
Date: 1998-04-27 10:01:40
Message-ID: Pine.LNX.3.96.980427095040.700A-100000@proxy.bazzanese.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Sun, 26 Apr 1998, Bruce Momjian wrote:

> > 
> > Seems there's a bug using ESCAPE character (\) on LIKE clause:
> > 
> > prova=> create table tmp ( a text);
> > CREATE
> > prova=> insert into tmp values('\\');
> > INSERT 178729 1
> > prova=> select * from tmp where a = '\\';
> > a
> > --
> > \\
> > (1 row)
> > 
> > prova=> select * from tmp where a like '%\\%';
> > a
> > -
> > (0 rows)
> > 
> > prova=> select * from tmp where a like '%\\\\%';
> > a
> > --
> > \\
> > (1 row)
> > 
> > -- how many \ do I have to use? 1, 2, 3, 4 or 5 ???
> > 
> > prova=> select * from tmp where a like '%\\\\\%';
> > a
> > --
> > \\
> > (1 row)
> >                                                   Jose'
> 
> The problem is that that \\ is need to input a backslash, and we support
> \ to escape special characters like %, so \\\\ is need to test for a
> backslash in a LIKE.  Is this not standard?  I suppose not.

The LIKE standard SQL92 has the keyword ESCAPE to specify a character
as escape, like this:

       SELECT * FROM my_table WHERE my_col LIKE '#_pluto' ESCAPE '#';

> Should we remove the special use of \ in LIKE?  Comments?

Obviously we need a character escape (back slash or other) to escape
_ or/and %, but before remove use of back slashes we need to have the
LIKE SQL92 syntax.
                                              Jose'


In response to

pgsql-hackers by date

Next:From: Michael MeskesDate: 1998-04-27 11:56:55
Subject: initdb problem and operator question
Previous:From: Gran ThyniDate: 1998-04-27 09:11:37
Subject: Re: [QUESTIONS] PostgreSQL and LDAP ?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group