pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Nikander <rob.nikander@gmail.com>
To: Postgres General <pgsql-general@postgresql.org>
Cc: Scot Kreienkamp <Scot.Kreienkamp@la-z-boy.com>
Subject: Re: help with aggregation query across a second text array column
Date: Mon, 12 Nov 2018 10:29:52 -0500
Message-ID: <FA3E2516-6BDC-46CB-B5B5-793AED4D7334@gmail.com> (raw)
In-Reply-To: <17082AAFC33A934082836458CB53494374D97CE2@MONDB03.na.lzb.hq>
References: <17082AAFC33A934082836458CB53494374D97CE2@MONDB03.na.lzb.hq>



> 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



view thread (3+ messages)  latest in thread

Message-ID: <FA3E2516-6BDC-46CB-B5B5-793AED4D7334@gmail.com>
Permalink:  ../FA3E2516-6BDC-46CB-B5B5-793AED4D7334@gmail.com/
Also on:    postgresql.org/message-id/FA3E2516-6BDC-46CB-B5B5-793AED4D7334@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: rob.nikander@gmail.com, Scot.Kreienkamp@la-z-boy.com
  Subject: Re: help with aggregation query across a second text array column
  In-Reply-To: <FA3E2516-6BDC-46CB-B5B5-793AED4D7334@gmail.com>
  References: <17082AAFC33A934082836458CB53494374D97CE2@MONDB03.na.lzb.hq> <FA3E2516-6BDC-46CB-B5B5-793AED4D7334@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox