Re: regexp searching in arrays not working?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Rhys Stewart" <rhys(dot)stewart(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: regexp searching in arrays not working?
Date: 2007-06-19 23:36:02
Message-ID: 18766.1182296162@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Rhys Stewart" <rhys(dot)stewart(at)gmail(dot)com> writes:
> Is regex searching not functioning (as i expect it to?)

~ expects the pattern on the right, not the left. So it's taking your
array entries as patterns, which don't match the data 'Trans'.

Since there's no "(array) ANY op scalar" syntax, the only way to get
this to work is to make a reverse-pattern-match operator that takes
the pattern on the left. You can glue one together from spare parts
easily enough:

regression=# create function reverse_regex(text,text) returns bool as
regression-# 'select $2 ~ $1' language sql immutable strict;
CREATE FUNCTION
regression=# create operator ~~~ (procedure = reverse_regex,
regression(# leftarg = text, rightarg = text);
CREATE OPERATOR

but I'm not sure what the performance will be like with a SQL function
in there...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Gardner 2007-06-19 23:56:34 Re: Excell
Previous Message Rhys Stewart 2007-06-19 23:15:43 regexp searching in arrays not working?