proposal for 8.5, listagg aggregate function, WIP patch

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема proposal for 8.5, listagg aggregate function, WIP patch
Дата
Msg-id 162867790912251029h2d0a7c5co13ae2a683ea521be@mail.gmail.com
обсуждение исходный текст
Ответы Re: proposal for 8.5, listagg aggregate function, WIP patch  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hello

I am returning to discussion
http://archives.postgresql.org/pgsql-hackers/2009-12/msg01378.php

I propose a new aggregate function - listagg. This function
concatenate values to string. If this function is used with two
parameters, then second parameter is used as delimiter. NULL input
values are ignored like other aggregates. If all values are NULL, then
result is NULL. When delimiter is omitted, then values are
concatenated without any delimiter.

This function could be replaced with
array_to_string(array_agg(),delimiter). It has same functionality, but
different implementation. listagg should be (and it is) faster,
because hasn't array overhead. In my tests - listagg is about 25%
faster. Mainly, listagg is shorter. Because we cannot well wrap
aggregates, I propose integrate this function. There are precedent -
function generate_sequences. It should be replaced by
generate_series(array_lower(), array_upper()), but it hasn't same
effectiveness.

Using:

postgres=# select * from country ;
    town    | state
------------+-------
 Prague     | cs
 Brno       | cs
 Bratislava | sk
 Kosice     | sk
(4 rows)

postgres=# select listagg(town,',') from country group by state;
      listagg
-------------------
 Bratislava,Kosice
 Prague,Brno
(2 rows)

Comments?

Regards
Pavel Stehule

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Matteo Beccati
Дата:
Сообщение: Re: PQescapeByteaConn and the new hex encoding
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: PQescapeByteaConn and the new hex encoding