pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: Ray O'Donnell <ray@rodonnell.ie>
To: pgsql-general@lists.postgresql.org
Subject: Re: Converting row elements into a arrays?
Date: Thu, 2 Mar 2023 15:57:55 -0600
Message-ID: <8f6144d5-25f7-bfe4-bc63-df318c08dc47@gmail.com> (raw)
In-Reply-To: <18b226e4-d018-c3b1-9dae-378bf67af346@rodonnell.ie>
References: <788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com>
	<18b226e4-d018-c3b1-9dae-378bf67af346@rodonnell.ie>

On 3/2/23 15:01, Ray O'Donnell wrote:
> On 02/03/2023 20:58, Ron wrote:
>> Postgresql 12.13
>>
>> Given the sample below, I'm looking for how to generate this output.  
>> It's like GROUP BY, but generating an array instead of an aggreate number.
>>   f1 | f2_array
>> ----+---------
>> 1 | {1,2,3}
>>    2 | {1,2,3,4}
>>    3 | {1,2}
>
> Something like this (off the top of my head)? -
>
>    select f1, array_agg(f2) as f2_array group by f1;
>
> Hope that helps (and that it's right!).

That did it.

-- 
Born in Arizona, moved to Babylonia.





view thread (11+ messages)  latest in thread

Message-ID: <8f6144d5-25f7-bfe4-bc63-df318c08dc47@gmail.com>
Permalink:  ../8f6144d5-25f7-bfe4-bc63-df318c08dc47@gmail.com/
Also on:    postgresql.org/message-id/8f6144d5-25f7-bfe4-bc63-df318c08dc47@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: ronljohnsonjr@gmail.com, ray@rodonnell.ie
  Subject: Re: Converting row elements into a arrays?
  In-Reply-To: <8f6144d5-25f7-bfe4-bc63-df318c08dc47@gmail.com>
  References: <788ab733-d0d1-7791-fb22-7c2724b08816@gmail.com> <18b226e4-d018-c3b1-9dae-378bf67af346@rodonnell.ie> <8f6144d5-25f7-bfe4-bc63-df318c08dc47@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