Andreas Kretschmer <akretschmer@spamfence.net> wrote:
> > they are being done over all rows. In this particular example you
> > happen to get the same result, but that's just because "avg(foo) over
> > partition by foo" is a dumb example --- it will necessarily just yield
> > identically foo. In more realistic computations the results would be
> > different.
>
> Okay, i believe you now ;-)
>
> I will try to find a case with different results ...
I have got it!
test=# select * from values;
id | value
----+-------
1 | 10
2 | 20
3 | 30
4 | 40
5 | 50
6 | 60
7 | 70
8 | 80
9 | 90
(9 rows)
Time: 0.240 ms
test=*# select id, sum(value) over (order by id) from values where id = 5;
id | sum
----+-----
5 | 50
(1 row)
Time: 0.352 ms
test=*# select * from (select id, sum(value) over (order by id) from values) foo where id = 5;
id | sum
----+-----
5 | 150
(1 row)
Time: 0.383 ms
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°