Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E0022 constant-condition

Condition that is always or never true from the schema.

CodeNameCategoryDefault
E0022constant-conditionsuspiciouswarn

What it reports

  • col IS NULL in WHERE on a NOT NULL column 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.