Re: Regular expression query - Mailing list pgsql-sql

From Tom Lane
Subject Re: Regular expression query
Date
Msg-id 825.967177355@sss.pgh.pa.us
Whole thread Raw
In response to Regular expression query  (Rodger Donaldson <rodgerd@diaspora.gen.nz>)
Responses Re: Regular expression query  (Oliver Seidel <os10000@in-medias-res.com>)
Re: Regular expression query  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-sql
Rodger Donaldson <rodgerd@diaspora.gen.nz> writes:
> SELECT url 
> FROM sites
> WHERE url ~ url || '\\s+'

> While this concatenation works with the LIKE directive (ie LIKE url || '%'),
> postgresql barfs on it in a regexp with the error:

> ERROR:  Unable to identify an operator '||' for types 'bool' and 'unknown'
>     You will have to retype this query using an explicit cast

LIKE and ~ do not have the same precedence.  See
http://www.postgresql.org/docs/postgres/operators.htm.
~ and || actually fall in the same category ("all other") and therefore
are grouped left-to-right; so you're getting (url ~ url) || '...'.

> The other aspect of this is that it seems that postgresql's regexp engine
> doesn't understand some expected regexps; I've tried both escaped and
> unescaped versions of, eg \w, \s, \n and so on a pg seems to ignore them.

The regexp package we currently use implements POSIX 1003.2 regexps
(see src/backend/regex/re_format.7).  I believe there is an item on the
TODO list about upgrading the regexp parser to something more modern
... feel free to hop on that project if it's bugging you ...
        regards, tom lane


pgsql-sql by date:

Previous
From: Yury Don
Date:
Subject: Re: [GENERAL] Getting the result of a query using COUNT(*)
Next
From: Andreas Tille
Date:
Subject: RE: Create table in functions