Re: CREATE AGGREGATE array_cat - Mailing list pgsql-hackers

From Vik Fearing
Subject Re: CREATE AGGREGATE array_cat
Date
Msg-id d07b415b-232a-3fa1-b6fa-779db621f034@postgresfriends.org
Whole thread Raw
In response to Re: CREATE AGGREGATE array_cat  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: CREATE AGGREGATE array_cat
List pgsql-hackers
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.


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

vik=# CREATE AGGREGATE array_cat (anyarray)
vik-# (
vik(#     sfunc = array_cat,
vik(#     stype = anyarray,
vik(#     initcond = '{}'
vik(# );
CREATE AGGREGATE

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

-- 
Vik Fearing



pgsql-hackers by date:

Previous
From: "Andres Freund"
Date:
Subject: Re: PATCH: Batch/pipelining support for libpq
Next
From: "David G. Johnston"
Date:
Subject: Re: CREATE AGGREGATE array_cat