Re: range intervals in window function frames

Поиск
Список
Период
Сортировка
От Vincent Veyron
Тема Re: range intervals in window function frames
Дата
Msg-id 1292325168.2312.38.camel@asus-1001PX.home
обсуждение исходный текст
Ответ на range intervals in window function frames  (Daniel Popowich <danielpopowich@gmail.com>)
Ответы Re: range intervals in window function frames  (Daniel Popowich <danielpopowich@gmail.com>)
Список pgsql-general
[sent you a personal email by mistake - slightly corrected query posted
to the list]

Le dimanche 12 décembre 2010 à 10:55 -0500, Daniel Popowich a écrit :
> Hello all!
>
> I need to do moving averages over time series data and was hoping
> window functions could solve the problem for me, but it doesn't look
> like 8.4 or even 9.0 implementations are quite there, yet.
>
> Currently, if I have this table:
>
>   create table sample (
>       ts    timestamp,
>       value integer
>   );
>   create index sample_ts on sample (ts);

> What I would LIKE to do is this:
>
>   select *, avg(ts) over(order by ts range (interval '5 min') preceding)
>          from sample order by ts;
>

This?


select t1.ts, t1.value, (select avg(t2.value) from (select value from
sample where (t1.ts-ts)::INTERVAL <= interval '5 minutes' and ts<t1.ts)
as t2) from sample t1;

--
Vincent Veyron
http://marica.fr/
Progiciel de gestion des dossiers de contentieux et d'assurance pour le service juridique




В списке pgsql-general по дате отправления:

Предыдущее
От: MICHÁLEK Jan Mgr.
Дата:
Сообщение: create language 'plpythonu' on win failed
Следующее
От: Peter Geoghegan
Дата:
Сообщение: Re: create language 'plpythonu' on win failed