From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Philipp Kraus <philipp(dot)kraus(at)tu-clausthal(dot)de> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: array_agg to array |
Date: | 2018-05-16 07:00:46 |
Message-ID: | CAFj8pRDg7bcUBbmNoN84igJNmYmQprw3T+izY5n6zLQUNG5b6Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi
2018-05-16 8:14 GMT+02:00 Philipp Kraus <philipp(dot)kraus(at)tu-clausthal(dot)de>:
> 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?
>
> Thanks
>
maybe you want array_to_string function
postgres=# select array['a','b'];
┌───────┐
│ array │
╞═══════╡
│ {a,b} │
└───────┘
(1 row)
postgres=# select array_to_string(array['a','b'],'');
┌─────────────────┐
│ array_to_string │
╞═════════════════╡
│ ab │
└─────────────────┘
(1 row)
Regards
Pavel
>
> Phil
>
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2018-05-16 07:07:15 | Re: Function to set up variable inside it |
Previous Message | Philipp Kraus | 2018-05-16 06:14:45 | array_agg to array |