Обсуждение: inconsistent functionality with LIKE operator

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

inconsistent functionality with LIKE operator

От
Phuong Ma
Дата:
I'm using PostgreSQL version 7.1, and I'm having trouble with the LIKE
statement.  How would I find the value "a\bc"?  I tried using the
backslash to escape it: LIKE 'a\\b%';

If I specify: LIKE 'a\\bc', then it works, but if I wanted it to look
for consecetive characters after the c, using the %, then it returns
other values besides what I'm looking for.

I also have the same problem with percent (%).  I have a test string
with the value "ab%c", and I want to look for that using LIKE.  I tried:
LIKE 'ab\%c', LIKE 'ab%%', and LIKE 'ab\%_', but these statements not
only returned what I was looking for, but also other values:
"abc","ABC", and "Abc".

Phuong

Re: inconsistent functionality with LIKE operator

От
Tom Lane
Дата:
Phuong Ma <pma@commandprompt.com> writes:
> I'm using PostgreSQL version 7.1, and I'm having trouble with the LIKE
> statement.  How would I find the value "a\bc"?  I tried using the
> backslash to escape it: LIKE 'a\\b%';

I think you need four backslashes.  The string-literal parser eats one
level of backslashes, but you need the pattern that arrives at LIKE
to look like "a\\b%".

BTW, "PostgreSQL version 7.1" does not exist yet.

            regards, tom lane