null-comparison
What it does
Section titled “What it does”Reports = NULL, <> NULL and != NULL.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”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;...Configuration
Section titled “Configuration”sql: lint: rules: null-comparison: warn # off, warn (default), errorEnabled by the presets: sql/sqlfluff.
Suppress one line with sudsy-disable-next-line null-comparison in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| sqlfluff | CV05 |
full |