E0022 constant-condition
Condition that is always or never true from the schema.
| Code | Name | Category | Default |
|---|---|---|---|
E0022 | constant-condition | suspicious | warn |
What it reports
col IS NULLinWHEREon aNOT NULLcolumn of a schema table: never true. Usually the wrong column, or a check that can never fire.- A column compared with itself (
a.x = a.x,x <> x), in any clause:=,<=,>=are true for every non-NULL value and<>,<,>never are. Usually a copy-paste slip in a join condition.
Example
SELECT o.id FROM orders o JOIN users u ON u.id = o.user_id WHERE u.email IS NULL;
warning[E0022]: Column 'users.email' is NOT NULL: IS NULL is never true
--> q.sql:1:66
|
1 | SELECT o.id FROM orders o JOIN users u ON u.id = o.user_id WHERE u.email IS NULL;
| ^^^^^^^
= help: Remove the condition, or test a nullable column
Notes
A column on the optional side of an outer join can be NULL whatever its definition (LEFT JOIN orders o ... WHERE o.id IS NULL finds users without orders), so it is not reported. Neither are columns of subqueries, CTEs and views, statements with template tags, nor IS NOT NULL (always true, but harmless).
Configuring
# sqlsift.toml
[rules]
constant-condition = "error" # or "off"
Or for a single line: -- sqlsift:disable E0022. The examples use the schema on the Rules page.