From: David Johnston <polobo@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: Re: Using regexp_matches in the WHERE clause
Date: Thu, 29 Aug 2013 06:43:57 -0700 (PDT)
Message-ID: <1377783837680-5768926.post@n5.nabble.com> (raw)
In-Reply-To: <1377781964520-5768923.post@n5.nabble.com>
References: <k8vmbm$1fg$1@ger.gmane.org>
<E72D307E-D276-4FF6-8E05-8434C6370AB8@yahoo.com>
<1377781964520-5768923.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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.h...
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: polobo@yahoo.com
Subject: Re: Using regexp_matches in the WHERE clause
In-Reply-To: <1377783837680-5768926.post@n5.nabble.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox