Re: [GENERAL] complex custom aggregate function

2009-02-09 Thread Scara Maccai
I think I've found a solution myself to the moving average problem, so I'm posting it here in case it works for some others (and so that everybody can check that I'm doing it right and in the "best" way...) Basically I'm 1) saving all the couples (timestamp, double) of an aggregation into an arr

Re: R: R: [GENERAL] complex custom aggregate function

2009-02-02 Thread Scara Maccai
Paolo Saudin wrote: > I use a master table with a "fulldate" field and filled with sequential dates > to > fill gaps when meteo data is missing. I'm sorry, I still don't get it: how can you be sure that postgresql won't call perl_sliding_mean with not-ordered timestamps-data? I don't mean only

R: R: [GENERAL] complex custom aggregate function

2009-02-02 Thread Paolo Saudin
>-Messaggio originale- >Da: pgsql-general-ow...@postgresql.org >[mailto:pgsql-general-ow...@postgresql.org] Per conto di Scara Maccai >Inviato: lunedì 2 febbraio 2009 10.36 >A: Paolo Saudin; pgsql-general@postgresql.org >Cc: pgsql-general >Oggetto: Re: R: [GE

Re: R: [GENERAL] complex custom aggregate function

2009-02-02 Thread Scara Maccai
> Paolo Saudin wrote: > For that purpose, a sliding mean calculation I use the following > > CREATE TABLE tbl_ayas > ( > fulldate timestamp without time zone NOT NULL, > id_1 real, -- temperature > id_2 real, -- pressure > .. > CONSTRAINT tbl_ayas_pkey PRIMARY KEY (fulldate) > )

R: [GENERAL] complex custom aggregate function

2009-02-01 Thread Paolo Saudin
>-Messaggio originale- >Da: pgsql-general-ow...@postgresql.org >[mailto:pgsql-general-ow...@postgresql.org] Per conto di Scara Maccai >Inviato: venerdì 30 gennaio 2009 9.36 >A: pgsql-general@postgresql.org >Oggetto: [GENERAL] complex custom aggregate function > >H

Re: [GENERAL] complex custom aggregate function

2009-01-30 Thread Marc Mamin
Oops, I meant group by floor(h_q-x) instead of group by (h_q-x)/1 Marc Mamin > select H,A > FROM > ( > select min(h_q) as H, avg(x) as A > group by h_q/1 > union all > select min(h_q), avg(x) > group by (h_q-0.25)/1 > union all > select min(h_q), avg(x) > group by (h_q-0.50)/1 > union a

Re: [GENERAL] complex custom aggregate function

2009-01-30 Thread Marc Mamin
... HTH, Marc Mamin -Original Message- From: pgsql-general-ow...@postgresql.org on behalf of Scara Maccai Sent: Fri 1/30/2009 1:45 PM To: pgsql-general@postgresql.org Subject: Re: [GENERAL] complex custom aggregate function Gregory Stark wrote: > From what I read of your > descr

Re: [GENERAL] complex custom aggregate function

2009-01-30 Thread Scara Maccai
Gregory Stark wrote: > From what I read of your > description you want to produce one record per input record. Exactly. > 8.4 Will have OLAP Window functions which can implement things like > moving averages. Using 8.3: could I do it caching all the values "somewhere" in a custom aggregation

Re: [GENERAL] complex custom aggregate function

2009-01-30 Thread Gregory Stark
Scara Maccai 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

[GENERAL] complex custom aggregate function

2009-01-30 Thread Scara Maccai
Hi all, I have a table like: value int, quarter timestamp I need an aggregate function that gives back the maximum "value" using this algorithm: AVG of the first hour (first 4 quarters) (AVG0) same as above, but 1 quarter later (AVG1) same as above, but n quarters later (AVGn) result: th