Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X4AnL-0006M5-NF for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Jul 2014 15:25:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X4AnL-0005qs-5V for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Jul 2014 15:25:31 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X4AnJ-0005nv-JK for pgsql-bugs@postgresql.org; Mon, 07 Jul 2014 15:25:29 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1X4AnG-000501-OV for pgsql-bugs@postgresql.org; Mon, 07 Jul 2014 15:25:27 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1X4AnG-0000T8-1f for pgsql-bugs@postgresql.org; Mon, 07 Jul 2014 08:25:26 -0700 Date: Mon, 7 Jul 2014 08:25:26 -0700 (PDT) From: David G Johnston To: pgsql-bugs@postgresql.org Message-ID: <1404746726037-5810751.post@n5.nabble.com> In-Reply-To: <20140707135824.2752.47779@wrigleys.postgresql.org> References: <20140707135824.2752.47779@wrigleys.postgresql.org> Subject: Re: BUG #10889: Cannot add 2 floats from regular expression MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 2.2 (++) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org jakub.vrbas wrote > The following bug has been logged on the website: > > Bug reference: 10889 > Logged by: Jakub Vrbas > Email address: > jakub.vrbas@ > PostgreSQL version: 9.1.13 > Operating system: Debian > Description: > > I have test_column (of type character varying). If I parse a float by > regular expression, it isn't possible to add it to another float from > regular expression. > > Example: > > SELECT > (regexp_matches(test_column, '([0-9\.]*)'))[1]::float > + > (regexp_matches(test_column, '([0-9\.]*)'))[1]::float > FROM test_table > > Results in "ERROR: functions and operators can take at most one set > argument" > > Example 2 is OK: > SELECT > float_column > + > float_column > FROM ( > SELECT > (regexp_matches(test_column, '([0-9\.]*)'))[1]::float AS float_column > FROM test_table > ) foo regexp_matches() returns a SETOF text[] If it is in a FROM then each row of the set gets doubled and a single row per input is output. If it is in the SELECT-list that doesn't work. You have to use a scalar subquery to make it work. SELECT (SELECT (regexp_matches('1.3', '([0-9\.]*)'))[1])::float + (SELECT (regexp_matches('2.3', '([0-9\.]*)'))[1])::float ; Suggest wrapping it in a function - or making a "regexp_matches_single" function that behaves similarly but returns a single text[] instead of a SETOF text[] David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/BUG-10889-Cannot-add-2-floats-from-regular-expression-tp5810748p5810751.html Sent from the PostgreSQL - bugs mailing list archive at Nabble.com. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs