Re: help with aggregation query across a second text array column

From: Rob Nikander <rob(dot)nikander(at)gmail(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Cc: Scot Kreienkamp <Scot(dot)Kreienkamp(at)la-z-boy(dot)com>
Subject: Re: help with aggregation query across a second text array column
Date: 2018-11-12 15:29:52
Message-ID: FA3E2516-6BDC-46CB-B5B5-793AED4D7334@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Nov 12, 2018, at 9:40 AM, Scot Kreienkamp <Scot(dot)Kreienkamp(at)la-z-boy(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marko Krajnc 2018-11-12 16:48:04 Re: libwinpthread-1.dll missing in PostgreSQL 11.0-1 for Windows
Previous Message Thomas Kellerer 2018-11-12 15:10:05 Re: libwinpthread-1.dll missing in PostgreSQL 11.0-1 for Windows