Re: Using regexp_matches in the WHERE clause - Mailing list pgsql-sql

From David Johnston
Subject Re: Using regexp_matches in the WHERE clause
Date
Msg-id 1377783837680-5768926.post@n5.nabble.com
Whole thread Raw
In response to Re: Using regexp_matches in the WHERE clause  (spulatkan <seckinpulatkan@hotmail.com>)
List pgsql-sql
spulatkan wrote
> so following is enough to get the rows that matches regular expression

> 

This is bad form even if it works.  If the only point of the expression is
to filter rows it should appear in the WHERE clause.  The fact that
regexp_matches(...) behaves in this way at all is, IMO, a flaw of the
implementation.


> on pgadmin the column type is shown as text[] thus I also do not
> understand why array_length on where condition does not work for this.

> 

This works because the array_length formula is applied once to each "row" of
the returned set.  

As mentioned before it makes absolutely no sense to evaluate a set-returning
function within the WHERE clause and so attempting to do so causes a fatal
exception.  For my usage I've simply written a wrapper function that
implements the same basic API as regexp_matches but that returns a scalar
"text[]" instead of a "setof text[]".  It makes coding these kinds of
queries easier if you know/understand the fact that your matching will never
cause more than 1 row to be returned.  If zero rows are returned I return an
empty array and the normal 1-row case returns the matching array.

David J.






--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Using-regexp-matches-in-the-WHERE-clause-tp5733684p5768926.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.



pgsql-sql by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: CTAGS for PL/pgSQL ?
Next
From: Luca Ferrari
Date:
Subject: Re: CTAGS for PL/pgSQL ?