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

Re: Simple like filter

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Ruzsinszky Attila <ruzsinszky(dot)attila(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Simple like filter
Date: 2009-08-27 15:17:04
Message-ID: 407d949e0908270817n118fe0eck91860d3cab30e1f7@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Thu, Aug 27, 2009 at 11:39 AM, Ruzsinszky
Attila<ruzsinszky(dot)attila(at)gmail(dot)com> wrote:
> 11111_123456 (varchar(20))
>
> I would like a where like SQL command.
> I tried this: like E'11\_%' -> wrong!
> like E'11\_______' -> good (with 7 piece of _ characters!)

You either want E'11\\_%' or you want '11\_%' with
standard_conforming_strings enabled. If you use E'11\_%' the backslash
is getting eaten before the like comparison even starts and the string
you're comparing with is just 11_% with _ used as a meta character.

You can also do  s LIKE '%Q_%' ESCAPE 'Q'

-- 
greg
http://mit.edu/~gsstark/resume.pdf

In response to

pgsql-novice by date

Next:From: Steve TDate: 2009-08-27 15:27:18
Subject: Speeding up 'bulk' delete (and/or seeing what is going on whilethe delete is being processed)
Previous:From: Lennin CaroDate: 2009-08-27 14:39:38
Subject: Re: compilation error

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