As you can see in this answer, in many SQL engines you can use the IS DISTINCT FROM
clause which will always return a True
or False
value.
More info: Most SQL engines use Three-valued logic. This means that a conditional can return True
, False
or, in case of comparison with a NULL value, Unknown
.
So, as an example, in a table like
A query like
SELECT * FROM table WHERE col <> 1
would return
since 1 <> NULL
doesn't return True
but Unknown
.
Instead, a query like
SELECT * FROM table WHERE col IS DISTINCT FROM 1
would return
since 1 IS DISTINCT FROM NULL
returns True
.
WITH ctx AS(SELECT 123 AS n0, NULL AS n1) SELECT n0 FROM ctx WHERE ctx.n1 < 130 OR ctx.n1 is NULL
– Orangutan