E0018 null-comparison
Comparison with NULL using = or <> is never true.
| Code | Name | Category | Default |
|---|---|---|---|
E0018 | null-comparison | suspicious | warn |
What it reports
A comparison operator (=, <>, !=, <, <=, >, >=) with a NULL literal operand, and CASE x WHEN NULL. Any comparison with NULL is NULL, so the condition never holds and the WHEN branch never runs.
Example
SELECT name FROM users WHERE email = NULL;
warning[E0018]: Comparison with NULL using '=' is never true
--> q.sql:1:30
|
1 | SELECT name FROM users WHERE email = NULL;
| ^^^^^
= help: Use IS NULL to test for NULL
Fixed:
SELECT name FROM users WHERE email IS NULL;
Notes
Assignments (UPDATE users SET email = NULL), IS [NOT] DISTINCT FROM NULL and MySQL's NULL-safe <=> are not comparisons in this sense and are not reported.
Configuring
# sqlsift.toml
[rules]
null-comparison = "error" # or "off"
Or for a single line: -- sqlsift:disable E0018. The examples use the schema on the Rules page.