Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

91
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda