Re: complex custom aggregate function

From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: m_lists(at)yahoo(dot)it
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: complex custom aggregate function
Date: 2009-01-30 11:12:55
Message-ID: 87pri5m4i0.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Scara Maccai <m_lists(at)yahoo(dot)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!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Monnerie 2009-01-30 11:23:49 Re: [GENERAL] Encoding problem using pg_dumpall
Previous Message Igor Katson 2009-01-30 11:09:18 Plproxy functions inside transactions and Pl/pgsql exception handling