public inbox for [email protected]
help / color / mirror / Atom feedFrom: Romain Carl <[email protected]>
To: [email protected]
Subject: Window functions: frame-adhering aggregate without ORDER BY clause
Date: Mon, 26 Jun 2023 13:44:39 +0200
Message-ID: <[email protected]> (raw)
References: <[email protected]>
Hi Listers,
among the window tests (src/test/regress/expected/window.out), I noticed
the presence of tests that rely upon the order of rows not determined by
any ORDER BY clause, such as:
SELECT sum(unique1) over (rows between 2 preceding and 2 following
exclude no others),
unique1, four
FROM tenk1 WHERE unique1 < 10;
Expected result:
sum | unique1 | four
-------+-----------+------
7 | 4 | 0
13 | 2 | 2
22 | 1 | 1
26 | 6 | 2
29 | 9 | 1
31 | 8 | 0
32 | 5 | 1
23 | 3 | 3
15 | 7 | 3
10 | 0 | 0
(10 rows)
The current row's frame and, consequently, the result of the sum
aggregate depend on the order produced by the sequential scan of table
tenk1. Since such order is, in general, not part of PG's defined
behavior, what purpose do the tests that rely upon it serve?
Following up to that, how is an EXCLUDE GROUP defined to behave in
absence of any ORDER BY clause? It seems to exclude the entire window
frame according to this test:
SELECT sum(unique1) over (rows between 2 preceding and 2 following
exclude group),
unique1, four
FROM tenk1 WHERE unique1 < 10;
Expected result:
sum | unique1 | four
-------+-----------+------
| 4 | 0
| 2 | 2
| 1 | 1
| 6 | 2
| 9 | 1
| 8 | 0
| 5 | 1
| 3 | 3
| 7 | 3
| 0 | 0
(10 rows)
Thanks in advance and best regards,
Romain
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Window functions: frame-adhering aggregate without ORDER BY clause
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox