Re: Grouping, Aggregate, Min, Max - Mailing list pgsql-general

From David Johnston
Subject Re: Grouping, Aggregate, Min, Max
Date
Msg-id 1386949350894-5783318.post@n5.nabble.com
Whole thread Raw
In response to Re: Grouping, Aggregate, Min, Max  (Misa Simic <misa.simic@gmail.com>)
List 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.


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: invisible dependencies on a table?
Next
From: John R Pierce
Date:
Subject: Re: design for multiple time series