Re: array_agg to array - Mailing list pgsql-general

From Torsten Förtsch
Subject Re: array_agg to array
Date
Msg-id CAKkG4_kTQgG4tymL0_U=_+sNubUBWuUCZHGnKMDfQwxqVaqcFA@mail.gmail.com
Whole thread Raw
In response to array_agg to array  (Philipp Kraus <philipp.kraus@tu-clausthal.de>)
Responses Re: array_agg to array
List pgsql-general
On Wed, May 16, 2018 at 8:14 AM, Philipp Kraus <philipp.kraus@tu-clausthal.de> wrote:
Hello,

I have got a function with a reg expr to split chemical formulas e.g. H2O -> H2 O.

CREATE OR REPLACE FUNCTION daimon.text2sumformula(text) RETURNS text[] AS $$
    select array_agg(i::text) as e from ( select unnest( regexp_matches( $1, '[0-9]*[A-Z][a-z]?\d*|\((?:[^()]*(?:\(.*\))?[^()]*)+\)\d+', 'g') ) ) i;
$$ LANGUAGE SQL IMMUTABLE;

For H2O I get an array with {(H2),(O)}
How I can return the inner elements as text, I would like to get {H2,O} without round brackets?

like this?
 
postgres=# select array_agg(i[1]) as e from regexp_matches( 'H2O', '[0-9]*[A-Z][a-z]?\d*|\((?:[^()]*(?:\(.*\))?[^()]*)+\)\d+', 'g') t(i);
  e     
--------
{H2,O}
(1 row)


pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Function to set up variable inside it
Next
From: Philipp Kraus
Date:
Subject: Re: array_agg to array