Re: Windowing functions vs aggregates - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Windowing functions vs aggregates
Date
Msg-id 4136ffa0904140625s578ac1e4ye784c7a1b5b4c4fa@mail.gmail.com
Whole thread Raw
In response to Windowing functions vs aggregates  (Teodor Sigaev <teodor@sigaev.ru>)
Responses Re: Windowing functions vs aggregates  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
2009/4/14 Teodor Sigaev <teodor@sigaev.ru>:
> select avg(s)::int4 OVER () from foo;

You can put the cast outside the window expression such as:

postgres=# select s,(avg(s) OVER (range between unbounded preceding
and current row))::int4 from foo;s | avg
---+-----1 |   22 |   23 |   2
(3 rows)


However, I'm kind of confused by that result. Why does the range
"between unbounded preceding and current row" seem to be doing the
average of the whole result set? This is not related to the cast:

postgres=# select s,avg(s) OVER (range between unbounded preceding and
current row) from foo;s |        avg
---+--------------------1 | 2.00000000000000002 | 2.00000000000000003 | 2.0000000000000000
(3 rows)


I haven't recompiled recently and I do recall some bug fixes a while
back. Was this that? I'm recompiling now.






-- 
greg


pgsql-hackers by date:

Previous
From: Teodor Sigaev
Date:
Subject: Windowing functions vs aggregates
Next
From: Euler Taveira de Oliveira
Date:
Subject: Re: Why isn't stats_temp_directory automatically created?