Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
comparing two fields that may be null

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

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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)
over 4 years ago · Santiago Trujillo Report

0

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)
over 4 years ago · Santiago Trujillo Report

0

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;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!