Re: Escaping underscores in LIKE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Richard Huxton" <dev(at)archonet(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Escaping underscores in LIKE
Date: 2001-03-09 14:39:54
Message-ID: 6656.984148794@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Richard Huxton" <dev(at)archonet(dot)com> writes:
>> You need more backslashes. Don't forget the string-literal parser eats
>> one level of backslashes, before LIKE ever gets to see the pattern.

> Thanks Tom, as a 2-stage process it all makes sense. Tried it out in PHP too
> and I end up with four backslashes (3 stages).

> Another DOH! item for my notes.

BTW, in 7.1 you can do

foo LIKE 'a#_b' ESCAPE '#'

(for '#' use whatever you want) to switch to a different escape
character that's not special to upstream processing. Probably nicer
than dealing with four or more backslashes ...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brent R. Matzelle 2001-03-09 15:17:04 Re: Re: pgsql for Python
Previous Message De Leeuw Guy 2001-03-09 11:37:37 Create trigger problem :