469,646 Members | 1,298 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

Migrating between versions. Problem with regexp

Dear friends,

I have the following problem.

libvar=# select version();
version
----------------------------------------------------------------
PostgreSQL 7.2.3 on i386-pc-bsdi4.0.1, compiled by GCC 2.7.2.1
(1 row)

libvar=# select '\\a\\\\\\.' ~ '\\a\\\\\\.';
?column?
----------
f
(1 row)
=======================================

libvar=# select version();

version
--------------------------------------------------------------------------------------------------------------
PostgreSQL 8.0.0beta1 on i686-pc-linux-gnu, compiled by GCC gcc (GCC)
3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)
(1 row)

libvar=# select '\\a\\\\\\.' ~ '\\a\\\\\\.';
ERROR: invalid regular expression: invalid escape \ sequence

I am using:
This is perl, v5.6.0 built for i386-bsdos
When I receive a text from CGI I made quotemeta over it to avoid symbols
that may be met in regular expressions.
Then I made DBI->quote over the same string to avoid any sql injection;
The problem is that I use cyrillic and quotemeta put before every
cyrillic character a \.
Then DBI->quote make \ to \\.
And then when I use this string in regular expression in Postgres I
recevie an error in the new version of postgres.
Could anyone sugest solution to my problem.
10x in advance.
Kaloyan

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #1
4 1585
Kaloyan Iliev Iliev <ne***@faith.digsys.bg> writes:
libvar=# select '\\a\\\\\\.' ~ '\\a\\\\\\.';
ERROR: invalid regular expression: invalid escape \ sequence


7.4 and later are stricter about the use of \ than prior versions; see
http://www.postgresql.org/docs/7.4/s...CAPE-SEQUENCES
You could go back to (approximately) the old behavior by changing
regex_flavor to "extended".

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #2
Thank you
Kaloyan

Tom Lane wrote:
Kaloyan Iliev Iliev <ne***@faith.digsys.bg> writes:

libvar=# select '\\a\\\\\\.' ~ '\\a\\\\\\.';
ERROR: invalid regular expression: invalid escape \ sequence


7.4 and later are stricter about the use of \ than prior versions; see
http://www.postgresql.org/docs/7.4/s...CAPE-SEQUENCES
You could go back to (approximately) the old behavior by changing
regex_flavor to "extended".

regards, tom lane


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #3
Dear Tom Lane,
I still haven't read all the documentation but I find the following.
If I escape with \\ latin letters it OK, but if escape with \\
cyrillic letters then it is a mistake.

libvar=# select '\\a\' ~* '\\a\';
?column?
----------
f
(1 row)

libvar=# select '\\a\\' ~* '\\a\\';
ERROR: invalid regular expression: invalid escape \ sequence
libvar=# select '\\a\\' ~* '\\a\';
?column?
----------
f
(1 row)

libvar=# select '\\a\' ~* '\\a\\';
ERROR: invalid regular expression: invalid escape \ sequence

So I understand that you can't adapt it to all languages and alphabets
but in case this is an error and can be fixed I report it.
Kaloyan

Tom Lane wrote:
Kaloyan Iliev Iliev <ne***@faith.digsys.bg> writes:

libvar=# select '\\a\\\\\\.' ~ '\\a\\\\\\.';
ERROR: invalid regular expression: invalid escape \ sequence


7.4 and later are stricter about the use of \ than prior versions; see
http://www.postgresql.org/docs/7.4/s...CAPE-SEQUENCES
You could go back to (approximately) the old behavior by changing
regex_flavor to "extended".

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #4
Kaloyan Iliev Iliev <ne***@faith.digsys.bg> writes:
I still haven't read all the documentation but I find the following.
If I escape with \\ latin letters it OK, but if escape with \\
cyrillic letters then it is a mistake.


No, you're missing the point: there are certain escapes that mean
something, and it rejects the rest. Backslash is not a general-purpose
quoting character.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Tom Loredo | last post: by
10 posts views Thread by Markus Enders | last post: by
6 posts views Thread by guy | last post: by
4 posts views Thread by =?Utf-8?B?QXJqdW4=?= | last post: by
4 posts views Thread by Matt | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.