Re: Substring function incorrect when searching for '@.'

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Mike G(dot)" <mike(at)thegodshalls(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Substring function incorrect when searching for '@.'
Date: 2004-10-12 23:00:16
Message-ID: 8170.1097622016@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Mike G." <mike(at)thegodshalls(dot)com> writes:
> 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/static/functions-matching.html

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Fahad G. 2004-10-13 00:23:27 'configure' bug on Mac OS X 10.3.5
Previous Message Mike G. 2004-10-12 22:35:17 Substring function incorrect when searching for '@.'