Skip to content

group-order-style

SQLstyleno fixdefault: offsql/sqlfluff

Reports a GROUP BY or ORDER BY clause that lists both column names or expressions and column positions (1, 2), or that lists them in the other way than the first such clause of the file.

Positions are short but depend on the order of the select list: a column added to the front changes what GROUP BY 1 means, with no error. A clause that mixes the two is read in two ways.

To fix, use names in every clause, or positions in every one.

Reported
...
select a, b from t group by a, 2;
with c as (select a from t) select * from c;
select x.a from (select * from t) as x;
...
sql:
lint:
rules:
group-order-style: warn # off (default), warn, error

Enabled by the presets: sql/sqlfluff.

Suppress one line with sudsy-disable-next-line group-order-style in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
sqlfluff AM06 full