Re: WARNING: nonstandard use of escape in a string literal

Поиск
Список
Период
Сортировка
От Bill Moran
Тема Re: WARNING: nonstandard use of escape in a string literal
Дата
Msg-id 20091223153211.d2d82f60.wmoran@potentialtech.com
обсуждение исходный текст
Ответ на WARNING: nonstandard use of escape in a string literal  ("Patrick M. Rutkowski" <rutski89@gmail.com>)
Ответы Re: WARNING: nonstandard use of escape in a string literal  ("Patrick M. Rutkowski" <rutski89@gmail.com>)
Список pgsql-general
In response to "Patrick M. Rutkowski" <rutski89@gmail.com>:

> I just ran something like:
> =============================================
> UPDATE my_table SET colname = NULL WHERE colname ~ '^\s*$'
> =============================================
>
>
> I got the following warnings/hints as a result:
> =============================================
> WARNING: nonstandard use of escape in a string literal
> HINT: USE the escape string syntax for escapes, e.g., E'\r\n'.
> UPDATE 500
> =============================================
>
>
> Oddly it actually updated, and did just exactly what I wanted! :-)
>
> So what am I to make of those weird hints and warning?

The SQL spec says that inside '', strings are to be interpreted exactly,
except for the string '', which is converted to '.

Obviously, 99% of the world thinks they should be able to use \ to
escape special characters (like \n and \t).  PostgreSQL has historically
supported the more common use and not been strict to the standard.

This is changing.  Newer versions of PG will (someday) no longer support
that syntax, and the warnings are alerting you to code that will stop
working when that happens.

In any event, you can work around this using the string escape syntax
(i.e. WHERE colname ~ E'^\s*$') and the official documentation is here:
http://www.postgresql.org/docs/8.4/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS

--
Bill Moran
http://www.potentialtech.com
http://people.collaborativefusion.com/~wmoran/

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

Предыдущее
От: Christophe Pettus
Дата:
Сообщение: 12/08 SFPUG meeting, "Operator Exclusion Constraints," video now available
Следующее
От: "Patrick M. Rutkowski"
Дата:
Сообщение: Re: WARNING: nonstandard use of escape in a string literal