PG Bug reporting form <noreply@postgresql.org> writes:
> I'm seeing inconsistent results for an ORDER BY in combination with GROUPING
> SETS.
Yup. Your example actually works correctly as of HEAD (v18-to-be):
regression=# select * from (values (1, 1), (1, 2), (2,1), (2,2)) as t (a,b)
where a=1
group by grouping sets ((b),(a,b))
order by a, b;
a | b
---+---
1 | 1
1 | 2
| 1
| 2
(4 rows)
but I'm afraid there's zero chance of back-patching the fix,
as it's far too invasive (and under-tested, for now) for that.
> This might be the same bug as
> https://www.postgresql.org/message-id/CAL48EtKDHCKnOkLdSgOmgBZBcahU2zpBqyzeET_ZM74uNZBFHg@mail.gmail.com
Indeed. Richard Guo recently completed the fix I alluded to in that
thread:
https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=247dea89f
https://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=f5050f795
regards, tom lane