Skip to content

Group by a column written in parentheses in GROUPING SETS, ROLLUP and CUBE to close #3152 - #3206

Open
aliassar wants to merge 1 commit into
AlaSQL:mainfrom
aliassar:fix-3152-grouping-sets-parens
Open

aliassar wants to merge 1 commit into
AlaSQL:mainfrom
aliassar:fix-3152-grouping-sets-parens

Conversation

@aliassar

@aliassar aliassar commented Dec 1, 2026

Copy link
Copy Markdown

(a) parses as a UniOp with no operator, so decartes and rollup in src/select/rollup.js didn't see a Column and grouped it under the key (a). The SELECT column a then wasn't matched to that key, so it read the first row of the group instead of NULL when a was outside the set.

The fix takes bare() of each item inside GROUPING SETS, ROLLUP and CUBE first (the same unwrap equals() uses since #3088), so GROUPING SETS((a), (b)), ROLLUP((a), b) and CUBE((a), (b)) give the same rows as without the parentheses. ((a)) works too.

A plain GROUP BY (a) is left as it is. Unwrapping there skips the nick that compileSelectGroup0 gives top-level columns, and GROUP BY (t1.a), (t2.a) on a join would then mix up the two a columns. The last test case checks that.

Tests: new test/test3152.js (fails on main, passes here), yarn test passes, and the dialect, run-state, binding and parity checks pass locally. Parity only shows differences for the new test.

Not covered here: a composite set like GROUPING SETS((a, b), a) and the empty set () still don't parse.

Fixes #3152

… CUBE to close AlaSQL#3152

(a) parses as a UniOp without an operator, so the grouping set code did not
see it as a column and the column outside the set kept its value instead of
NULL. Take the bare expression first, as equals() does since AlaSQL#2721.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GROUPING SETS with parenthesised sets gives a value instead of NULL for a column outside the set

1 participant