Re: CREATE AGGREGATE array_cat

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: CREATE AGGREGATE array_cat
Дата
Msg-id CAKFQuwY-fZ3STg5GB1Rc7MMDnwp-LHgo97MPWUzAVJD4WObQ+w@mail.gmail.com
обсуждение исходный текст
Ответ на Re: CREATE AGGREGATE array_cat  (Vik Fearing <vik@postgresfriends.org>)
Ответы Re: CREATE AGGREGATE array_cat  (Chapman Flack <chap@anastigmatix.net>)
Список 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 по дате отправления:

Предыдущее
От: Vik Fearing
Дата:
Сообщение: Re: CREATE AGGREGATE array_cat
Следующее
От: Vik Fearing
Дата:
Сообщение: Re: pl/pgsql feature request: shorthand for argument and local variable references