pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Gauthier <davegauthierpg@gmail.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: How to get CASE statement to recognize null ?
Date: Wed, 10 Mar 2021 14:46:53 -0500
Message-ID: <2188918.1615405613@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMBRECCXKr4x8NOtCrumAet80_uDGq_PZ45vHf7Qa8YB7+ES5A@mail.gmail.com>
References: <CAMBRECCXKr4x8NOtCrumAet80_uDGq_PZ45vHf7Qa8YB7+ES5A@mail.gmail.com>

David Gauthier <davegauthierpg@gmail.com> writes:
>     dvdb=# select
>       CASE col1
>         WHEN null THEN 'z'
>         ELSE col1
>        END as col1,
>        col2
>      from foo;

This test is equivalent to "col1 = null" which will always fail.
You could try something like

	CASE WHEN col1 IS NULL THEN ... ELSE ... END

Although I think the particular thing you're doing here would
be better solved with COALESCE(col1, 'z').

			regards, tom lane





view thread (4+ messages)  latest in thread

Message-ID: <2188918.1615405613@sss.pgh.pa.us>
Permalink:  ../2188918.1615405613@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2188918.1615405613@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, davegauthierpg@gmail.com
  Subject: Re: How to get CASE statement to recognize null ?
  In-Reply-To: <2188918.1615405613@sss.pgh.pa.us>
  References: <CAMBRECCXKr4x8NOtCrumAet80_uDGq_PZ45vHf7Qa8YB7+ES5A@mail.gmail.com> <2188918.1615405613@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox