dbTalk Databases Forums  

[BUGS] \ escapes in check constraint strings?

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] \ escapes in check constraint strings? in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bruno Wolff III
 
Posts: n/a

Default [BUGS] \ escapes in check constraint strings? - 07-16-2004 , 04:48 PM






I see the following behaivor on 7.4.3 and 7.4 stable from about a week ago:
bruno=> create table test ();
CREATE TABLE
bruno=> alter table test add constraint test2 check('\\' = '');
ALTER TABLE
bruno=> \d test
Table "public.test"
Column | Type | Modifiers
--------+------+-----------
Check constraints:
"test2" CHECK ('\\'::text = ''::text)

bruno=> select '\\';
?column?
----------
\
(1 row)

I didn't see \\ left as \\ in at least some 7.3 versions.

I think this is a bug, but maybe there are different escape rules for
strings in check constraints.

In the real case that this derives from I was getting a different number
of backslashes than I expected in a regular expression.

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Reply With Quote
  #2  
Old   
Bruno Wolff III
 
Posts: n/a

Default Re: [BUGS] \ escapes in check constraint strings? - 07-16-2004 , 05:05 PM






On Fri, Jul 16, 2004 at 16:49:25 -0500,
Bruno Wolff III <bruno (AT) wolff (DOT) to> wrote:
Quote:
I see the following behaivor on 7.4.3 and 7.4 stable from about a week ago:
bruno=> create table test ();
CREATE TABLE
bruno=> alter table test add constraint test2 check('\\' = '');
ALTER TABLE
bruno=> \d test
Table "public.test"
Column | Type | Modifiers
--------+------+-----------
Check constraints:
"test2" CHECK ('\\'::text = ''::text)

bruno=> select '\\';
?column?
----------
\
(1 row)

I didn't see \\ left as \\ in at least some 7.3 versions.

I think this is a bug, but maybe there are different escape rules for
strings in check constraints.

In the real case that this derives from I was getting a different number
of backslashes than I expected in a regular expression.
I think I have figured out what was going on. It looks like [\] in 7.3
regular expressions would try to match a \, but in 7.4 the ] was escaped
resulting in an invalid regular expression. So the real problem was
that in 7.3 I was using something like '[\\]' when I should have been
using '[\\\\]'.
While I was trying to figure out what was going on I was confused by
the \d output putting 2 \s where there was only one. Presumably this
is so the output could be used to recreate the constraint. This seems
reasonable, but it this particular case confused me.

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
  #3  
Old   
Peter Eisentraut
 
Posts: n/a

Default Re: [BUGS] \ escapes in check constraint strings? - 07-16-2004 , 05:09 PM



Bruno Wolff III wrote:
Quote:
I see the following behaivor on 7.4.3 and 7.4 stable from about a
week ago: bruno=> create table test ();
CREATE TABLE
bruno=> alter table test add constraint test2 check('\\' = '');
ALTER TABLE
bruno=> \d test
Table "public.test"
Column | Type | Modifiers
--------+------+-----------
Check constraints:
"test2" CHECK ('\\'::text = ''::text)
It prints the SQL source code for the check constraint. There is no
bug, AFAICS.

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.