Thread: Referencing parts captured by round brackets in a regex in 8.4.13
Hello, how to get rid of this warning on a PostgreSQL 8.4.13 prompt? # select 'axxxxxyz' ~ '(.)\1\1'; WARNING: nonstandard use of escape in a string literal LINE 1: select 'axxxxxyz' ~ '(.)\1\1'; ^ HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. ?column? ---------- f (1 row) The table 9-18 at http://www.postgresql.org/docs/8.4/static/functions-matching.html suggests that using \1 as above should be ok.... Thank you Alex
On 03/22/2013 08:53 AM, Alexander Farber wrote: > Hello, > > how to get rid of this warning > on a PostgreSQL 8.4.13 prompt? > > > # select 'axxxxxyz' ~ '(.)\1\1'; > WARNING: nonstandard use of escape in a string literal > LINE 1: select 'axxxxxyz' ~ '(.)\1\1'; > ^ > HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. > ?column? > ---------- > f > (1 row) > > > The table 9-18 at > http://www.postgresql.org/docs/8.4/static/functions-matching.html > suggests that using \1 as above should be ok.... > > Thank you > Alex > > Try \\1\\1
Thank you, this works better, but - On Fri, Mar 22, 2013 at 3:57 PM, Rob Sargent <robjsargent@gmail.com> wrote: > On 03/22/2013 08:53 AM, Alexander Farber wrote: >> >> # select 'axxxxxyz' ~ '(.)\1\1'; >> WARNING: nonstandard use of escape in a string literal >> LINE 1: select 'axxxxxyz' ~ '(.)\1\1'; >> ^ >> HINT: Use the escape string syntax for escapes, e.g., E'\r\n'. >> ?column? >> ---------- >> f >> (1 row) >> >> >> The table 9-18 at >> http://www.postgresql.org/docs/8.4/static/functions-matching.html >> suggests that using \1 as above should be ok.... the result is correctly "true" now, but the warning is still there, why? # select 'axxxxxyz' ~ '(.)\\1\\1'; WARNING: nonstandard use of \\ in a string literal LINE 1: select 'axxxxxyz' ~ '(.)\\1\\1'; ^ HINT: Use the escape string syntax for backslashes, e.g., E'\\'. ?column? ---------- t (1 row)
2013/3/22 Alexander Farber <alexander.farber@gmail.com>: > the result is correctly "true" now, > but the warning is still there, why? > > # select 'axxxxxyz' ~ '(.)\\1\\1'; > WARNING: nonstandard use of \\ in a string literal > LINE 1: select 'axxxxxyz' ~ '(.)\\1\\1'; > ^ > HINT: Use the escape string syntax for backslashes, e.g., E'\\'. > ?column? > ---------- > t > (1 row) > Please, check this part of the docs (note the Caution): http://www.postgresql.org/docs/8.4/static/sql-syntax-lexical.html#SQL-BACKSLASH-TABLE -- Victor Y. Yegorov
On 22 March 2013 16:08, Alexander Farber <alexander.farber@gmail.com> wrote:
--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.
Thank you, this works better, but -
the result is correctly "true" now,
but the warning is still there, why?WARNING: nonstandard use of \\ in a string literal
# select 'axxxxxyz' ~ '(.)\\1\\1';LINE 1: select 'axxxxxyz' ~ '(.)\\1\\1';HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
^
?column?
----------
t
(1 row)
Because backslash is not normally a valid escape character in an SQL string literal.
You can turn off the warning in your settings, or you can be explicit about wanting a string literal that can include such escape characters by using the E'<string>' notation.
I seem to recall that there's a string literal notation specific to regular expressions as well (R'<regular expression>'?), but I may be mixing up databases...
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.
Thanks, I finally get it - this works fine: # select 'axxxxxyz' ~ E'(.)\\1\\1'; ?column? ---------- t (1 row) # select 'ОШИБББКА' ~ E'(.)\\1\\1'; ?column? ---------- t (1 row)