Re: I'm using both window and agg, is this expected sorting behavior?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jinser <aimer(at)purejs(dot)icu>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: I'm using both window and agg, is this expected sorting behavior?
Date: 2023-10-04 16:32:56
Message-ID: 2600124.1696437176@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

jinser <aimer(at)purejs(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-10-04 16:54:18 Re: Strategies for converting UTC data to local windows for arbitrary resolutions and timezones
Previous Message jinser 2023-10-04 16:05:19 I'm using both window and agg, is this expected sorting behavior?