Обсуждение: Simple like filter

Поиск
Список
Период
Сортировка

Simple like filter

От
Ruzsinszky Attila
Дата:
Hi,

My data are look like:
1_123456
11_123456
111_123456
1111_123456
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!)

What would I have to do if the second part of the numbers (after the
_ character) will be different lenght?

TIA,
Ruzsi

Re: Simple like filter

От
Greg Stark
Дата:
On Thu, Aug 27, 2009 at 11:39 AM, Ruzsinszky
Attila<ruzsinszky.attila@gmail.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