SUM up some values with NULL in it, we get a value.

WITH base AS (
SELECT
1 AS num
UNION ALL
SELECT
2 AS num
UNION ALL
SELECT
NULL AS num
)
SELECT
SUM(num)
FROM
base


gives us

3


However, if one would add some values up, we get a NULL when one of them is NULL.

SELECT
NULL + 10 AS null_plus_num


gives us a

NULL


Published: by ;

Lei Ma (2020). 'Deal with NULL in Postgres', Datumorphism, 11 April. Available at: https://datumorphism.leima.is/til/data/postgres.deal-with-null/.