Re: Grouping, Aggregate, Min, Max

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Grouping, Aggregate, Min, Max
Date: 2013-12-13 15:42:30
Message-ID: 1386949350894-5783318.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Re:custom aggregate:

I'd probably try building a two dimensional array in the state transition
function. Take the new value and check if it is adjacent to the last value
in the last bin of the current state. If so add it to that bin. If not
create a new bin and store it there. Requires sorted input.

You could also just store all the values encountered and at the end group
them into bins after sorting internally. That way you just need to get the
partition right - not the order by and sub-groups.

The final output is just a call to string_agg though you would have to
unnest the array in a custom manner since unnest() flattens
multiple-dimensional arrays. See a recent thread for specifics.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Grouping-Aggregate-Min-Max-tp5783279p5783318.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jamin Shanti 2013-12-13 17:49:03 Re: out of memory issue
Previous Message Adrian Klaver 2013-12-13 15:30:27 Re: invisible dependencies on a table?