Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lK4nK-0007zK-8i for pgsql-general@arkaria.postgresql.org; Wed, 10 Mar 2021 19:46:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lK4nJ-0001vT-5X for pgsql-general@arkaria.postgresql.org; Wed, 10 Mar 2021 19:46:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lK4nI-0001vM-UB for pgsql-general@lists.postgresql.org; Wed, 10 Mar 2021 19:46:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lK4nG-00066E-QC for pgsql-general@postgresql.org; Wed, 10 Mar 2021 19:46:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 12AJkrmK2188919; Wed, 10 Mar 2021 14:46:53 -0500 From: Tom Lane To: David Gauthier cc: Postgres General Subject: Re: How to get CASE statement to recognize null ? In-reply-to: References: Comments: In-reply-to David Gauthier message dated "Wed, 10 Mar 2021 14:41:59 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2188917.1615405613.1@sss.pgh.pa.us> Date: Wed, 10 Mar 2021 14:46:53 -0500 Message-ID: <2188918.1615405613@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Gauthier 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