Re: How to get CASE statement to recognize null ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Gauthier <davegauthierpg(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to get CASE statement to recognize null ?
Date: 2021-03-10 19:46:53
Message-ID: 2188918.1615405613@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

David Gauthier <davegauthierpg(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Gauthier 2021-03-10 20:00:43 Re: How to get CASE statement to recognize null ?
Previous Message David Gauthier 2021-03-10 19:41:59 How to get CASE statement to recognize null ?