Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VF2W3-0008FZ-Je for pgsql-sql@arkaria.postgresql.org; Thu, 29 Aug 2013 13:44:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VF2W2-0005qz-Sz for pgsql-sql@arkaria.postgresql.org; Thu, 29 Aug 2013 13:44:02 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VF2W1-0005qs-R9 for pgsql-sql@postgresql.org; Thu, 29 Aug 2013 13:44:01 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VF2Vy-0006uY-CM for pgsql-sql@postgresql.org; Thu, 29 Aug 2013 13:44:01 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1VF2Vx-0006bl-M7 for pgsql-sql@postgresql.org; Thu, 29 Aug 2013 06:43:57 -0700 Date: Thu, 29 Aug 2013 06:43:57 -0700 (PDT) From: David Johnston To: pgsql-sql@postgresql.org Message-ID: <1377783837680-5768926.post@n5.nabble.com> In-Reply-To: <1377781964520-5768923.post@n5.nabble.com> References: <1377781964520-5768923.post@n5.nabble.com> Subject: Re: Using regexp_matches in the WHERE clause MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 4.5 (++++) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org 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. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql