sum() over (partition by order) question - Mailing list pgsql-hackers

From Pavel Stehule
Subject sum() over (partition by order) question
Date
Msg-id 162867790812311334k2afdb530nddf801b6b9c8cf2d@mail.gmail.com
Whole thread Raw
Responses Re: sum() over (partition by order) question  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: sum() over (partition by order) question  ("Jaime Casanova" <jcasanov@systemguards.com.ec>)
List pgsql-hackers
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 | 3 93 | 12
|3 93 | 22 | 3 93 | 16 | 3 93 | 16 | 3 93 | 16 | 3
 
(13 rows)

postgres=# select sum(a) over (partition by b order by a), a, b from foo;sum | a  | b
-----+----+---  2 |  1 | 1  2 |  1 | 1  6 |  2 | 1  6 |  2 | 1 14 |  4 | 1 14 |  4 | 1 19 |  5 | 1 11 | 11 | 3 23 | 12
|3 71 | 16 | 3 71 | 16 | 3 71 | 16 | 3 93 | 22 | 3
 
(13 rows)

I didn't expect so ORDER can change result of function sum. Please,
can somebody explain it?

regards
Pavel Stehule


pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: pg_dump roles support [Review]
Next
From: Tom Lane
Date:
Subject: Re: sum() over (partition by order) question