You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Review #2398 for code improvements: GROUP BY prefers a SELECT alias over a table column #2709
This is not a bug report. It is an invitation to look at #2398 again, because it decides between an alias and a table column differently from SQLite and from HAVING. The goal is to understand the change and decide whether anything should be improved. The notes below come from a quick read of the diff and a few runs, not from a full analysis.
The concern:
GROUP BY b takes the SELECT alias b even when the table has a column b.compileSelectGroup0 (src/424select.js) replaces a GROUP BY name with a copy of the aliased SELECT expression when the name is not a column in the SELECT list. It does not look at the source tables. SQLite and PostgreSQL group by the table column in that case:
CREATETABLEgt (a INT, b STRING); INSERT INTO gt VALUES (1, 'p'), (2, 'p'), (3, 'q');
SELECT CASE WHEN a >1 THEN 'big' ELSE 'small' END AS b, COUNT(*) AS n FROM gt GROUP BY b
-- AlaSQL: small 1, big 2 (grouped by the CASE). SQLite: groups by gt.b, 2 and 1 rows.
HAVING follows the SQLite rule since Let HAVING use a SELECT alias to close #887 #2672 (a source column wins over an alias, using query.defcols). One rule for both, in one place, would keep GROUP BY and HAVING consistent. Changing GROUP BY changes results that work consistently today, so it is a decision for the breaking list.
Activity
mathiasrw commentedon Oct 20, 2026
Decided 2026-10-21: 4.x keeps the current GROUP BY behaviour; 5.0 follows SQLite with the v4 rule available through a dialect. Tracked in #2710.
mathiasrw commentedon Nov 26, 2026
Will be covered by #2710.