Skip to content

count-star

SQLstyleno fixdefault: offsql/sqlfluff

Reports a COUNT of the constant 1 or 0, as in COUNT(1).

COUNT(*) is the standard form and counts rows. COUNT(1) and COUNT(0) give the same number, but a reader may wonder whether the constant matters, and some think it is faster, which it is not.

To fix, write COUNT(*).

Reported
...
select 1 union all select 2;
select 1 union distinct select 2;
...
select count(1), count(0), count(*), count(a) from t;
...
select a from t left join u on t.a = u.a;
...
sql:
lint:
rules:
count-star: warn # off (default), warn, error

Enabled by the presets: sql/sqlfluff.

Suppress one line with sudsy-disable-next-line count-star 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 CV04 full