Re: CREATE AGGREGATE array_cat

From: Vik Fearing <vik(at)postgresfriends(dot)org>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Vlad Bokov <vlad(at)razum2um(dot)me>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: CREATE AGGREGATE array_cat
Date: 2020-11-19 00:37:26
Message-ID: d07b415b-232a-3fa1-b6fa-779db621f034@postgresfriends.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11/18/20 11:19 PM, David G. Johnston wrote:
> On Wednesday, November 18, 2020, Vlad Bokov <vlad(at)razum2um(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2020-11-19 00:46:52 Re: CREATE AGGREGATE array_cat
Previous Message Andres Freund 2020-11-18 23:17:36 Re: PATCH: Batch/pipelining support for libpq