Re: Backslash Bug in ARE Class-Shorthand Escape?

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: Backslash Bug in ARE Class-Shorthand Escape?
Дата
Msg-id 3FD19298.9060107@joeconway.com
обсуждение исходный текст
Ответ на Re: Backslash Bug in ARE Class-Shorthand Escape?  (Joe Conway <mail@joeconway.com>)
Список pgsql-bugs
Joe Conway wrote:
> David Fetter wrote:
>> I have a little puzzlement.  In the first select, I double the
>> backslash and return true.  In the second, I don't and get false.
>> Have I missed something important in the docs?
>
> I don't know if it is clear in the docs anywhere wrt regex, but the
> string literal parser will consume one layer of backslashes on you. So
> in your first case '\\d' is fed into the regex matching function as '\d'
> (string literal parser sees \\ == escape \ == \), and in the second case
> '\d' is fed in as 'd' (string literal parser sees \d == escape d == d).
> The basic rule at work here is you need to double up all backslashes.
>

As a follow-up, there is a statement to this effect in the section on
LIKE, that applies, in part at least, to the regexes as well. See:
http://www.postgresql.org/docs/current/static/functions-matching.html

Specifically, about the 7th paragraph:

"Note that the backslash already has a special meaning in string
literals, so to write a pattern constant that contains a backslash you
must write two backslashes in an SQL statement. Thus, writing a pattern
that actually matches a literal backslash means writing four backslashes
in the statement. You can avoid this by selecting a different escape
character with ESCAPE; then a backslash is not special to LIKE anymore.
(But it is still special to the string literal parser, so you still need
two of them.)"

Part of this should probably be pulled out of the section on LIKE and
into the introduction for pattern matching in general.

Joe

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: Backslash Bug in ARE Class-Shorthand Escape?
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Failed regression test in postgresql-7.4