Re: Calculating a moving average - Mailing list pgsql-general

From Greg Stark
Subject Re: Calculating a moving average
Date
Msg-id 87y8en9tuu.fsf@stark.xeocode.com
Whole thread Raw
In response to Re: Calculating a moving average  ("Jim C. Nasby" <decibel@decibel.org>)
List pgsql-general
"Jim C. Nasby" <decibel@decibel.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Multiline plpython procedure
Next
From: "Dann Corbit"
Date:
Subject: Re: Calculating a moving average