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