Re: complex custom aggregate function - Mailing list pgsql-general

From Gregory Stark
Subject Re: complex custom aggregate function
Date
Msg-id 87pri5m4i0.fsf@oxford.xeocode.com
Whole thread Raw
In response to complex custom aggregate function  (Scara Maccai <m_lists@yahoo.it>)
Responses Re: complex custom aggregate function  (Scara Maccai <m_lists@yahoo.it>)
List pgsql-general
Scara Maccai <m_lists@yahoo.it> writes:

> It would be very easy if the input to the custom aggregate function was
> ordered (because I would keep 4 internal counters), but I guess there's
> no way of "forcing" the ordering of the input to the function, right?

You can with a subquery. Something like

 SELECT agg(foo) from (SELECT foo ORDER BY bar)

However that will produce one record per grouping. From what I read of your
description you want to produce one record per input record. There isn't any
efficient way to do that in current Postgres releases -- you would have to
have a subquery which executed for every record and retrieved the set of data
to aggregate.

8.4 Will have OLAP Window functions which can implement things like moving
averages.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!

pgsql-general by date:

Previous
From: Igor Katson
Date:
Subject: Plproxy functions inside transactions and Pl/pgsql exception handling
Next
From: Reg Me Please
Date:
Subject: PGSQL and Javascript