Re: [HACKERS] sum() over (partition by order) question

2008-12-31 Thread Pavel Stehule
2008/12/31 Tom Lane : > "Pavel Stehule" writes: >> so I have to modify query to get expected values >> postgres=# select a, b, last_value(a) over (partition by b), >> last_value(a) over (partition by b order by a RANGE BETWEEN UNBOUNDED >> PRECEDING AND UNBOUNDED FOLLOWING) from foo; > >> it shou

Re: [HACKERS] sum() over (partition by order) question

2008-12-31 Thread Pavel Stehule
2008/12/31 Tom Lane : > "Pavel Stehule" writes: >> so I have to modify query to get expected values >> postgres=# select a, b, last_value(a) over (partition by b), >> last_value(a) over (partition by b order by a RANGE BETWEEN UNBOUNDED >> PRECEDING AND UNBOUNDED FOLLOWING) from foo; > >> it shou

Re: [HACKERS] sum() over (partition by order) question

2008-12-31 Thread Tom Lane
"Pavel Stehule" writes: > so I have to modify query to get expected values > postgres=# select a, b, last_value(a) over (partition by b), > last_value(a) over (partition by b order by a RANGE BETWEEN UNBOUNDED > PRECEDING AND UNBOUNDED FOLLOWING) from foo; > it should be noticed in doc? It is -

Re: [HACKERS] sum() over (partition by order) question

2008-12-31 Thread Tom Lane
"Pavel Stehule" writes: > wrong > postgres=# select a, b, sum(a) over (w) from foo window w as > (partition by b order by a ROWS BETWEEN UNBOUNDED PRECEDING AND > UNBOUNDED FOLLOWING); Should be "over w". "over (w)" is a that modifies an existing window, not just a reference, and in particular

Re: [HACKERS] sum() over (partition by order) question

2008-12-31 Thread Pavel Stehule
2008/12/31 Tom Lane : > "Pavel Stehule" writes: >> I didn't expect so ORDER can change result of function sum. > > Read the stuff about window frames. The results you show are > exactly per spec. > I have to do it, when I tested last_value and first_value function I was surprised more - order by

Re: [HACKERS] sum() over (partition by order) question

2008-12-31 Thread Jaime Casanova
On Wed, Dec 31, 2008 at 4:34 PM, Pavel Stehule wrote: > Hello > > I am play with windows function. I was surprised so these queries has > different results. > > postgres=# select sum(a) over (partition by b), a, b from foo; AFAIUI, this means one sum per b value, the result in the sum column will

Re: [HACKERS] sum() over (partition by order) question

2008-12-31 Thread Tom Lane
"Pavel Stehule" writes: > I didn't expect so ORDER can change result of function sum. Read the stuff about window frames. The results you show are exactly per spec. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes

[HACKERS] sum() over (partition by order) question

2008-12-31 Thread Pavel Stehule
Hello I am play with windows function. I was surprised so these queries has different results. postgres=# select sum(a) over (partition by b), a, b from foo; sum | a | b -++--- 19 | 1 | 1 19 | 1 | 1 19 | 2 | 1 19 | 4 | 1 19 | 2 | 1 19 | 4 | 1 19 | 5 | 1 93 | 11 |