Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-08 Thread David G. Johnston
On Monday, January 8, 2024, Geoff Winkless wrote > > > Mildly interesting: you can pass column positions to GROUP BY and > ORDER BY but if you try to pass a position to GROUPING() (I wondered > if that would help the engine somehow) it fails: > The symbol 1 is ambigious - it can be the number or

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-08 Thread Geoff Winkless
On Mon, 8 Jan 2024 at 11:12, Geoff Winkless wrote: > What's even more of a head-scratcher is why fixing this this then > breaks the _first_ group's ORDERing. Ignore that. Finger slippage - looking back I realised I forgot the "=0" test after the GROUPING() call. It looks like I'm going to go wit

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-08 Thread Geoff Winkless
On Mon, 8 Jan 2024 at 10:23, Geoff Winkless wrote: > Seems there was a reason why I thought that: per the documentation: > > "The arguments to the GROUPING function are not actually evaluated, > but they must exactly match expressions given in the GROUP BY clause > of the associated query level."

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-08 Thread Geoff Winkless
On Sat, 6 Jan 2024 at 23:27, Geoff Winkless wrote: > Well yes. I assumed that since it's required that a group expression is in > the query itself that > the grouping values were taken from the result set, I have to admit to some > surprise that > they're calculated twice (three times?). Seems

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-06 Thread Geoff Winkless
On Sat, 6 Jan 2024, 19:49 Tom Lane, wrote: > "David G. Johnston" writes: > > Something does seem off here with the interaction between grouping sets > and > > order by. > > Yeah. I think Geoff is correct to identify the use of subqueries in > the grouping sets as the triggering factor. [snip]

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-06 Thread Tom Lane
"David G. Johnston" writes: > Something does seem off here with the interaction between grouping sets and > order by. Yeah. I think Geoff is correct to identify the use of subqueries in the grouping sets as the triggering factor. We can get some insight by explicitly printing the ordering value

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-06 Thread Geoff Winkless
On Sat, 6 Jan 2024 at 16:22, David G. Johnston wrote: > On Sat, Jan 6, 2024 at 8:38 AM Geoff Winkless wrote: >> because when gp_conc is 0, it should be ordering by the concat() value. > > Something does seem off here with the interaction between grouping sets and > order by. > I'm inclined to be

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-06 Thread Zhang Mingli
Hi, Zhang Mingli www.hashdata.xyz On Jan 6, 2024 at 23:38 +0800, Geoff Winkless , wrote: > > I was hoping to see > > gp_n | gp_conc | n | concat > --+-+--+ > 1 | 0 | NULL | n1x5 > 1 | 0 | NULL | n2x4 > 1 | 0 | NULL | n3x3 > 1 | 0 | NULL | n4x2 > 1 | 0 | NULL | n5x1 > 0 | 1

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-06 Thread David G. Johnston
On Sat, Jan 6, 2024 at 8:38 AM Geoff Winkless wrote: > On Fri, 5 Jan 2024 at 18:34, Zhang Mingli wrote: > > > > On Jan 6, 2024 at 01:38 +0800, Geoff Winkless , > wrote: > > > > > > Am I missing some reason why the first set isn't sorted as I'd hoped? > > > > > > Woo, it’s a complex order by, I t

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-06 Thread Geoff Winkless
On Fri, 5 Jan 2024 at 18:34, Zhang Mingli wrote: > > On Jan 6, 2024 at 01:38 +0800, Geoff Winkless , wrote: > > > Am I missing some reason why the first set isn't sorted as I'd hoped? > > > Woo, it’s a complex order by, I try to understand your example. > And I think the order is right, what’s you

Re: weird GROUPING SETS and ORDER BY behaviour

2024-01-05 Thread Zhang Mingli
Hi, Zhang Mingli www.hashdata.xyz On Jan 6, 2024 at 01:38 +0800, Geoff Winkless , wrote: > > Am I missing some reason why the first set isn't sorted as I'd hoped? Woo, it’s a complex order by, I try to understand your example. And I think the order is right, what’s your expected order result? `