Re: Converting row elements into a arrays?

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: Ray O'Donnell <ray(at)rodonnell(dot)ie>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Converting row elements into a arrays?
Date: 2023-03-02 21:57:55
Message-ID: 8f6144d5-25f7-bfe4-bc63-df318c08dc47@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2023-03-02 22:10:24 Re: Converting row elements into a arrays?
Previous Message Ron 2023-03-02 21:49:13 Re: Converting row elements into a arrays?