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 1w0NJs-001r0P-0Y for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Mar 2026 17:26:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0NJq-00AU9G-29 for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Mar 2026 17:26:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w0Mm3-00AHme-1q for pgsql-bugs@lists.postgresql.org; Wed, 11 Mar 2026 16:51:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w0Mm1-00000002AI9-2KWV for pgsql-bugs@lists.postgresql.org; Wed, 11 Mar 2026 16:51:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=rB9C+ZksBMf1pUxNeFr6Pq2bKClXJQ6M1IKoOE8v8sI=; b=l91ICzC8IJojuHEEOXFsP4gbHp o4pt1ErWkgIW/arcvqZbVKGq+LF6TWRcX2C2MDBJ6XGee8azzUiQ6oSxHxQKLFLDxRcDvVEGBaFHT Wzz3/k2Wefx4LlwjT/8dYI9VLt94s79VQCVTMyD3Ha9nXELlDqM/k3j8+6JFym+7htwPVO07RsY/V 57DCf8tSff65M131WdLkr4p9Ap40D/nTgcdQaEg90kfj08SdeU7qke8TQzB0e0cjDy4DROKZ6XQ4h sj3eCsnp86sOGFDUthzEp1/nQckm1BrIrFbBjrH8Jq+pcnrNp3SkQnYn/DQahZ+N5jSTZBkRrpYfW llLRB7fQ==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w0Mm0-003zjb-0J for pgsql-bugs@lists.postgresql.org; Wed, 11 Mar 2026 16:51:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0Mly-008CIu-0b for pgsql-bugs@lists.postgresql.org; Wed, 11 Mar 2026 16:51:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18 To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: michael.banck@credativ.de Reply-To: michael.banck@credativ.de, pgsql-bugs@lists.postgresql.org Date: Wed, 11 Mar 2026 16:50:07 +0000 Message-ID: <19428-d9ac6c4d84c0bc81@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19428 Logged by: Michael Banck Email address: michael.banck@credativ.de PostgreSQL version: 18.3 Operating system: n/a Description: =20 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 'hello world' AS arg INTO data; SELECT NULL AS selector INTO selectors; CREATE OR REPLACE FUNCTION func(name anyelement) RETURNS anyelement LANGUAGE sql STABLE STRICT AS $function$ SELECT CASE WHEN selector IS NULL THEN $1::text ELSE $1::inet::text END FROM (SELECT selector FROM selectors) $function$; SELECT func(arg) FROM data; On 17 or earlier, you get: func --------------------------- selector:foo(hello world) (1 row) func --------------------------- selector:bar(hello world) (1 row) func ------------- hello world (1 row) on 18 you get: ERROR: invalid input syntax for type inet: "hello world" CONTEXT: SQL function "func" statement 1 STATEMENT: SELECT func(arg) FROM data; I bisected this to 0dca5d68d7b. Looks like they depend on lazy evaluation in CASE via the subquery to check if the second argument is a valid inet, which no longer works after 0dca5d68d7b. Is that an intended change?