From: Tom Lane <tgl@sss.pgh.pa.us>
To: jinser <aimer@purejs.icu>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: I'm using both window and agg, is this expected sorting behavior?
Date: Wed, 04 Oct 2023 12:32:56 -0400
Message-ID: <2600124.1696437176@sss.pgh.pa.us> (raw)
In-Reply-To: <CAK3STzGxBU5oFXpDr2hsRbOKbRmfoqLXDC0irLKXQL32_ctg6w@mail.gmail.com>
References: <CAK3STzGxBU5oFXpDr2hsRbOKbRmfoqLXDC0irLKXQL32_ctg6w@mail.gmail.com>
jinser <aimer@purejs.icu> writes:
> This is what confuses me, I've tried many versions of pgsql, at least
> including 11-16, and the behavior is consistent with the above; but I
> feel that maybe the order by in the window function should not affect
> the final result.
Since you have not specified an ORDER BY for the overall query
result, the implementation is entitled to return the rows in
any order it pleases. Ours happens to sort by the window ordering
before computing the window functions, so that's what you get.
In this case anyway --- you shouldn't rely on that.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, aimer@purejs.icu
Subject: Re: I'm using both window and agg, is this expected sorting behavior?
In-Reply-To: <2600124.1696437176@sss.pgh.pa.us>
References: <CAK3STzGxBU5oFXpDr2hsRbOKbRmfoqLXDC0irLKXQL32_ctg6w@mail.gmail.com> <2600124.1696437176@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox