Re: CREATE AGGREGATE array_cat - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: CREATE AGGREGATE array_cat
Date
Msg-id CAKFQuwY-fZ3STg5GB1Rc7MMDnwp-LHgo97MPWUzAVJD4WObQ+w@mail.gmail.com
Whole thread Raw
In response to Re: CREATE AGGREGATE array_cat  (Vik Fearing <vik@postgresfriends.org>)
Responses Re: CREATE AGGREGATE array_cat  (Chapman Flack <chap@anastigmatix.net>)
List pgsql-hackers
On Wed, Nov 18, 2020 at 5:37 PM Vik Fearing <vik@postgresfriends.org> wrote:
On 11/18/20 11:19 PM, David G. Johnston wrote:
> On Wednesday, November 18, 2020, Vlad Bokov <vlad@razum2um.me> wrote:
>
>> Hi, I wonder why there's no function to aggregate arrays by
>> concatenation out of the box?
>>
>
> See array_agg(...)


Why?  That doesn't do what is wanted.


Sorry, I did not read closely enough.

I doubt there is any substantial resistance to including such a function but it would have to be written in C.


vik=# select array_agg(a) from (values (array[1]), (array[2])) as v(a);
 array_agg
-----------
 {{1},{2}}
(1 row)

And it's not too hard to work the system to get what you want even without a custom aggregate.

select array_agg(b) from (values (array[1]), (array[2])) as v(a), unnest(a) as w(b);

vik=# select array_cat(a) from (values (array[1]), (array[2])) as v(a);
 array_cat
-----------
 {1,2}
(1 row)


David J.

pgsql-hackers by date:

Previous
From: Vik Fearing
Date:
Subject: Re: CREATE AGGREGATE array_cat
Next
From: Vik Fearing
Date:
Subject: Re: pl/pgsql feature request: shorthand for argument and local variable references