Re: Calculating a moving average

From: Greg Stark <gsstark(at)mit(dot)edu>
To: "Jim C(dot) Nasby" <decibel(at)decibel(dot)org>
Cc: Greg Stark <gsstark(at)mit(dot)edu>, pgsql-general(at)postgresql(dot)org
Subject: Re: Calculating a moving average
Date: 2005-01-21 06:30:49
Message-ID: 87y8en9tuu.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Jim C. Nasby" <decibel(at)decibel(dot)org> writes:

> If you're feeling adventurous, you might look at Oracle's documentation
> on their analytic functions and see if you can come up with something
> generic for PostgreSQL.

I think the hard part of doing even a simple implementation is precisely the
point I raised about doing it in Perl or Python. Somehow you have to allocate
a static storage area specific to the call site. It's sort of like an
aggregate function call except of course that you're going to return a datum
for every record.

For a fuller implementation there are a lot more details. If I understand
correctly in Oracle you get to specify an ORDER BY clause and the equivalent
of a GROUP BY clause in the analytic function call. I think each call site can
even have its own order and grouping.

> Even if you only do a moving average function it would be a good start.

Actually my pet one would be a "rank" function. So you could do something like
"return the top 3 scoring players from each team". Currently the suggested way
to do it is by using an aggregate function to gather up the data in an array.

--
greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dann Corbit 2005-01-21 06:57:27 Re: Calculating a moving average
Previous Message Tom Lane 2005-01-21 06:30:30 Re: Multiline plpython procedure