proposal for 8.5, listagg aggregate function, WIP patch - Mailing list pgsql-hackers

From Pavel Stehule
Subject proposal for 8.5, listagg aggregate function, WIP patch
Date
Msg-id 162867790912251029h2d0a7c5co13ae2a683ea521be@mail.gmail.com
Whole thread Raw
Responses Re: proposal for 8.5, listagg aggregate function, WIP patch  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

Attachment

pgsql-hackers by date:

Previous
From: Matteo Beccati
Date:
Subject: Re: PQescapeByteaConn and the new hex encoding
Next
From: Andrew Dunstan
Date:
Subject: Re: PQescapeByteaConn and the new hex encoding