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