Null handling
SQL has an unconventional way of handling NULL
values, since it treats them as
unknown values. As a result, in SQL:
NULL
is not a value indicating a missing entry, but a placeholder for anything possible,NULL = NULL
evaluates toNULL
, since one cannot know if one unknown is equal to another unknown,NULL <> NULL
evaluates toNULL
, using same logic,- to check if a value is
NULL
, SQL introducesIS NULL
andIS NOT NULL
operators, DISTINCT column
may return multipleNULL
values.
For more information, check out the Postgres documentation.
PRQL, on the other hand, treats null
as a value, which means that:
null == null
evaluates totrue
,null != null
evaluates tofalse
,- distinct column cannot contain multiple
null
values.
PRQL
from employees
filter first_name == null
filter null != last_name
SQL
SELECT
*
FROM
employees
WHERE
first_name IS NULL
AND last_name IS NOT NULL
Note that PRQL doesn’t change how NULL
is compared between columns, for
example in joins. (PRQL compiles to SQL and so can’t change the behavior of the
database).
For more context or to provide feedback check out the discussion on issue #99.