GROUP BY 1, 2 groups by output columns by position. It's terse but
brittle: if the SELECT list is reordered, the query silently produces
different results. Also non-portable (some dialects reject ordinals in
newer modes).
Should fail
SELECT region, status, COUNT(*)
FROM orders
GROUP BY 1, 2;
Should pass
SELECT region, status, COUNT(*)
FROM orders
GROUP BY region, status;
Implementation hints
- Single-line rule in
sql_guard/rules/warnings.py.
- Regex:
r"\bGROUP\s+BY\s+\d+(\s*,\s*\d+)*\b" - matches GROUP BY 1 or
GROUP BY 1, 2, 3.
- Careful: don't trigger on
GROUP BY col1, col2 where the column names
happen to start with digits (rare but possible).
- Severity:
warning.
Estimated LOC: ~20 code + ~15 test.
GROUP BY 1, 2groups by output columns by position. It's terse butbrittle: if the SELECT list is reordered, the query silently produces
different results. Also non-portable (some dialects reject ordinals in
newer modes).
Should fail
Should pass
Implementation hints
sql_guard/rules/warnings.py.r"\bGROUP\s+BY\s+\d+(\s*,\s*\d+)*\b"- matchesGROUP BY 1orGROUP BY 1, 2, 3.GROUP BY col1, col2where the column nameshappen to start with digits (rare but possible).
warning.Estimated LOC: ~20 code + ~15 test.