Re: BUG #2391: "Similar to" pattern matching does not operate as documented - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #2391: "Similar to" pattern matching does not operate as documented
Date
Msg-id 21132.1144947341@sss.pgh.pa.us
Whole thread Raw
In response to BUG #2391: "Similar to" pattern matching does not operate as documented  ("Eric Noriega" <noriega@gwu.edu>)
List pgsql-bugs
"Eric Noriega" <noriega@gwu.edu> writes:
> db=# select 'tab' similar to 'a|b';
>  ?column?
> ----------
>  t

Yeah, this is a bug ... the cause can be seen by looking at the
underlying similar_escape() function, which converts a SIMILAR TO
pattern into a POSIX regex pattern:

regression=# select similar_escape('(a|b)', null);
 similar_escape
----------------
 ^(a|b)$
(1 row)

regression=# select similar_escape('a|b', null);
 similar_escape
----------------
 ^a|b$
(1 row)

regression=#

I believe that in the second case, ^ and $ bind more tightly than |
per POSIX rules.  So we need to put parens around the pattern to
prevent that.

Thanks for the report!

            regards, tom lane

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #2389: function within function return value
Next
From: Stephan Szabo
Date:
Subject: Re: BUG #2390: check constraint