Re: regexp searching in arrays not working? - Mailing list pgsql-general

From Tom Lane
Subject Re: regexp searching in arrays not working?
Date
Msg-id 18766.1182296162@sss.pgh.pa.us
Whole thread Raw
In response to regexp searching in arrays not working?  ("Rhys Stewart" <rhys.stewart@gmail.com>)
Responses Re: regexp searching in arrays not working?
Re: regexp searching in arrays not working?
List pgsql-general
"Rhys Stewart" <rhys.stewart@gmail.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

pgsql-general by date:

Previous
From: "Rhys Stewart"
Date:
Subject: regexp searching in arrays not working?
Next
From: David Gardner
Date:
Subject: Re: Excell