Re: help with aggregation query across a second text array column
Rob Nikander <rob.nikander@gmail.com>
From: Rob Nikander <rob.nikander@gmail.com>
To: Postgres General <pgsql-general@postgresql.org>
Cc: Scot Kreienkamp <Scot.Kreienkamp@la-z-boy.com>
Date: 2018-11-12T15:29:52Z
Lists: pgsql-general
> On Nov 12, 2018, at 9:40 AM, Scot Kreienkamp <Scot.Kreienkamp@la-z-boy.com> wrote:
> …
I’m not too confident in my answer here (there could be a better way), but this might help. You could use the `unnest` function to transform the array into multiple rows. For example, given a table like
create table t1 (env text, cls text, cls2 text[]);
I can query it like:
select env, string_agg(cls, ‘,’)
from (select env, cls from t1
union
select env, unnest(cls2) from t1) t
group by env;
Rob