Search Postgresql Archives

Re: Grouping, Aggregate, Min, Max

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux