Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w0Nio-001rIy-12 for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Mar 2026 17:51:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0Nim-00AldH-2W for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Mar 2026 17:51:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w0Nim-00Alcx-1l for pgsql-bugs@lists.postgresql.org; Wed, 11 Mar 2026 17:51:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w0Nil-00000001e3l-0dmG for pgsql-bugs@lists.postgresql.org; Wed, 11 Mar 2026 17:51:48 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 62BHpb051329232; Wed, 11 Mar 2026 13:51:37 -0400 From: Tom Lane To: michael.banck@credativ.de cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18 In-reply-to: <19428-d9ac6c4d84c0bc81@postgresql.org> References: <19428-d9ac6c4d84c0bc81@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 11 Mar 2026 16:50:07 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3707.1773251497.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 11 Mar 2026 13:51:37 -0400 Message-ID: <3708.1773251497@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > A colleague has complained to me that the following (minimal reproducer = he > could come up with) worked on pre-18, but no longer does on 18: > ... > SELECT CASE > WHEN selector IS NULL THEN $1::text > ELSE $1::inet::text > END > ... > I bisected this to 0dca5d68d7b. Looks like they depend on lazy evaluatio= n in > CASE via the subquery to check if the second argument is a valid inet, w= hich > no longer works after 0dca5d68d7b. Is that an intended change? We have never promised to avoid constant-folding within the subexpressions of a CASE [1]. So it was pure accident that this example worked before, and I don't think it's a bug that it doesn't work now. You could possibly make this logic work reliably by wrapping the cast-to-inet part in a volatile plpgsql function. regards, tom lane [1] https://www.postgresql.org/docs/current/functions-conditional.html#FUN= CTIONS-CASE