Replace = NULL and <> NULL with IS NULL and IS NOT NULL

Proprietary

Under three-valued logic a comparison with NULL evaluates to UNKNOWN rather than true, so col = NULL and col <> NULL match no rows. Rewrite them to the intended col IS NULL and col IS NOT NULL, changing only the compared operator so the rest of the statement is left untouched.

org.openrewrite.sql.antipattern.ReplaceNullComparisonWithIsNull

Optional

markSourceBoolean

Whether to mark each occurrence in source, and apply the fix where the rule remediates. Defaults to true; set to false to leave source untouched and report only to the data table, as an analysis-only pipeline requires.

mod run . --recipe=org.openrewrite.sql.antipattern.ReplaceNullComparisonWithIsNull

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.