Re: Using regexp_matches in the WHERE clause

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Using regexp_matches in the WHERE clause
Date: 2013-08-29 13:43:57
Message-ID: 1377783837680-5768926.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Luca Ferrari 2013-08-29 14:00:21 Re: CTAGS for PL/pgSQL ?
Previous Message Bruce Momjian 2013-08-29 13:33:11 Re: CTAGS for PL/pgSQL ?