Is there a comparison operator where a.unitnum = b.unitnum would be true if both a.unitnum and b.unitnum are null? Seems that a.unitnum IS b.unitnum is invalid
yes, there is IS DISTINCT FROM and IS NOT DISTINCT FROM
postgres=# \pset null ****
Null display is "****".
postgres=# select null = null;
┌──────────┐
│ ?column? │
╞══════════╡
│ **** │
└──────────┘
(1 row)
postgres=# select null is not distinct from null;
┌──────────┐
│ ?column? │
╞══════════╡
│ t │
└──────────┘
(1 row)
postgres=# select 10 = null;
┌──────────┐
│ ?column? │
╞══════════╡
│ **** │
└──────────┘
(1 row)
postgres=# select 10 is distinct from null;
┌──────────┐
│ ?column? │
╞══════════╡
│ t │
└──────────┘
(1 row)
postgres=# select 10 is not distinct from null;
┌──────────┐
│ ?column? │
╞══════════╡
│ f │
└──────────┘
(1 row)
postgres=# select 10 is not distinct from 20;
┌──────────┐
│ ?column? │
╞══════════╡
│ f │
└──────────┘
(1 row)
yes, there is, but it is recomended to not use it. here is sample:
t=# select null = null;
?column?
----------
(1 row)
t=# set transform_null_equals = on;
SET
t=# select null = null;
?column?
----------
t
(1 row)
UPDATE: apparently would work only for comparison column = NULL, not column = column:
t=# with s as (select null::int a, null::int b) select a <> b from s;
?column?
----------
(1 row)
so the shortest comparison would be coalesce:
t=# with s as (select null::int a, null::int b) select coalesce(a,b,0) = 0 from s;
?column?
----------
t
(1 row)
IF(a.unitnum IS null AND b.unitnum IS null)
THEN
RAISE NOTICE 'unitum field is null in both a and b tables'
ELSE
RAISE NOTICE 'unitum field is not null in at least one a or b tables'
END IF;