Skip site navigation (1) Skip section navigation (2)

Re: BUG #2391: "Similar to" pattern matching does not operate as documented

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Eric Noriega" <noriega(at)gwu(dot)edu>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2391: "Similar to" pattern matching does not operate as documented
Date: 2006-04-13 16:55:41
Message-ID: 21132.1144947341@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugs
"Eric Noriega" <noriega(at)gwu(dot)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

In response to

pgsql-bugs by date

Next:From: Raphael JacquotDate: 2006-04-13 17:02:58
Subject: BUG #2392: Feature request : point_ops
Previous:From: Tom LaneDate: 2006-04-13 16:51:15
Subject: Re: BUG #2389: function within function return value

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group