Re: Windowing functions vs aggregates

From: Greg Stark <stark(at)enterprisedb(dot)com>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Windowing functions vs aggregates
Date: 2009-04-14 13:25:33
Message-ID: 4136ffa0904140625s578ac1e4ye784c7a1b5b4c4fa@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2009/4/14 Teodor Sigaev <teodor(at)sigaev(dot)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 | 2
2 | 2
3 | 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.0000000000000000
2 | 2.0000000000000000
3 | 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Euler Taveira de Oliveira 2009-04-14 13:26:52 Re: Why isn't stats_temp_directory automatically created?
Previous Message Teodor Sigaev 2009-04-14 13:12:37 Windowing functions vs aggregates