Null-Safe Comparison With IS DISTINCT FROM
Compare two nullable columns without nulls silently dropping rows from a WHERE clause, using IS DISTINCT FROM instead of not-equal.
Code
SELECT
id,
legacy_email,
current_email
FROM user_migrations
WHERE legacy_email IS DISTINCT FROM current_email
AND resolved_at IS NULL
ORDER BY id;
-- Using legacy_email <> current_email instead would silently exclude every
-- row where either side is NULL, which is exactly the mismatch we want.Report a problem with this exampleOpens a pre-filled issue on GitHub.