Make a plpgsql function which will iterate over the rows on which the
moving average is to be done (FOR row IN SELECT), of course use the
correct order, then use an array as a FIFO, add a row to the moving
average and push it, pop the old one and substract it.
Roundoff errors will bite your
I personally use 3 seperate triggers on most occasions, depending on how
different the action for each seperate action is, it's just easier for me and my
people to logically distinguish the functions that way, but the example in the
7.4 documentation for triggers is given using the form that i wrot
On Mon, 24 Jan 2005 08:32 pm, Alban Hertroys wrote:
> [EMAIL PROTECTED] wrote:
> > CREATE OR REPLACE FUNCTION get_bar_avg() RETURNS TRIGGER AS '
> > DECLARE
> > bar_record RECORD;
> > x INTEGER;
> > y DOUBLE PRECISION := 0;
> > BEGIN
> > IF TG_OP = ''INSERT'' THEN
> > y := y + NEW.ba
[EMAIL PROTECTED] wrote:
CREATE OR REPLACE FUNCTION get_bar_avg() RETURNS TRIGGER AS '
DECLARE
bar_record RECORD;
x INTEGER;
y DOUBLE PRECISION := 0;
BEGIN
IF TG_OP = ''INSERT'' THEN
y := y + NEW.bar;
...
RETURN NEW;
ELSIF TG_OP = ''DELETE'' THEN
x := 0;
...
Unless I'm grossly misunderstanding the problem i think that a trigger written
in PL/pgsql would work fine. Something like this:
CREATE TABLE foo (
foo_id SERIAL primary key,
foo TEXT);
CREATE TABLE bar (
foo_id INTEGER references foo,
bar_id SERIAL primary key,
bar DOUBLE PRECISION NOT NULL);
"Dann Corbit" <[EMAIL PROTECTED]> writes:
> If someone wanted to put arbitrary aggregates into PostgreSQL, I would
> suggest something akin to the "RED BRICK" API, or better yet, the ATLAS
> API:
I also found a good reference for the DB2's SQL2003 Standard OLAP functions:
http://publib.boulder.i
If someone wanted to put arbitrary aggregates into PostgreSQL, I would
suggest something akin to the "RED BRICK" API, or better yet, the ATLAS
API:
http://magna.cs.ucla.edu/atlas/
---(end of broadcast)---
TIP 8: explain analyze is your friend
"Jim C. Nasby" <[EMAIL PROTECTED]> 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
poin
On Fri, Jan 21, 2005 at 12:53:45AM -0500, Greg Stark wrote:
> "Vanole, Mike" <[EMAIL PROTECTED]> writes:
>
> > I need to calculate a moving average and I would like to do it with SQL,
> > or a Pg function built for this purpose. I'm on Pg 7.4. Is this possible
> > in Pg without a bunch of self joi
"Vanole, Mike" <[EMAIL PROTECTED]> writes:
> I need to calculate a moving average and I would like to do it with SQL,
> or a Pg function built for this purpose. I'm on Pg 7.4. Is this possible
> in Pg without a bunch of self joins, or is there a funtion available?
Unfortunately moving averages f
IMO-YMMV
>
>
>
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Vanole, Mike
> Sent: Wednesday, January 19, 2005 1:34 PM
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] Calculating a moving average
>
>
]
[mailto:[EMAIL PROTECTED] On
Behalf Of Vanole, Mike
Sent: Wednesday, January 19, 2005
1:34 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Calculating a
moving average
Hi,
I need to calculate a moving average and I would like to do
it with SQL, or a Pg function built for this
Title: Message
Hi,
I need to calculate
a moving average and I would like to do it with SQL, or a Pg function built for
this purpose. I'm on Pg 7.4. Is this possible in Pg without a bunch of self
joins, or is there a funtion available?
Thanks,
Mike
13 matches
Mail list logo