dbTalk Databases Forums  

[BUGS] Substring function incorrect when searching for '@.'

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


Discuss [BUGS] Substring function incorrect when searching for '@.' in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mike G.
 
Posts: n/a

Default [BUGS] Substring function incorrect when searching for '@.' - 10-12-2004 , 05:36 PM






To reproduce:

create a table with a data type of varchar (50) and name it email

insert into this table the following values:
test1 (AT) anyemail (DOT) com

Execute the following statement:
SELECT CASE WHEN count(substring(email FROM '@.')) > 0 THEN count(substring(email FROM '@.')) ELSE 0 END, email FROM your_schema.your_table GROUP BY email;

Result with be equal to 1 / True. It should be 0 / False.

If you execute the above but replace '@.' with '@a' it will also return 1 / True is correct.

The only time it fails for me is if the @ is immediately followed by a period.

7.3.4 using psql via pgadminIII under cygwin.

Mike


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] Substring function incorrect when searching for '@.' - 10-12-2004 , 06:01 PM






"Mike G." <mike (AT) thegodshalls (DOT) com> writes:
Quote:
create a table with a data type of varchar (50) and name it email

insert into this table the following values:
test1 (AT) anyemail (DOT) com

Execute the following statement:
SELECT CASE WHEN count(substring(email FROM '@.')) > 0 THEN count(substring(email FROM '@.')) ELSE 0 END, email FROM your_schema.your_table GROUP BY email;

Result with be equal to 1 / True. It should be 0 / False.
This is not a bug; it's a POSIX regular expression match, and it's
behaving exactly as it should ('.' matches any character).

The particular syntax substring(char-expression FROM char-expression)
is not defined by SQL99 --- their regular-expression construct requires
a third parameter (ESCAPE something). We have chosen to interpret it
as a POSIX regular-expression match. See
http://www.postgresql.org/docs/7.3/s...-matching.html

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match


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.