Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

92
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda