Skip to content

null-comparison

SQLcorrectnessno fixdefault: warnsql/sqlfluff

Reports = NULL, <> NULL and != NULL.

A comparison with NULL gives NULL, not true or false, so the condition is never true and the query returns no rows (or, with <>, none of the rows that it should).

To fix, write IS NULL or IS NOT NULL.

Reported
select a from t where a = null and b <> null and c != NULL and null = d;
select a from t where a is null and b is not null and c = 'null';
...
select distinct a from t;
...
sql:
lint:
rules:
null-comparison: warn # off, warn (default), error

Enabled by the presets: sql/sqlfluff.

Suppress one line with sudsy-disable-next-line null-comparison 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 CV05 full