BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: michael(dot)banck(at)credativ(dot)de
Subject: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18
Date: 2026-03-11 16:50:07
Message-ID: 19428-d9ac6c4d84c0bc81@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19428
Logged by: Michael Banck
Email address: michael(dot)banck(at)credativ(dot)de
PostgreSQL version: 18.3
Operating system: n/a
Description:

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?

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-03-11 17:51:37 Re: BUG #19428: Lazy evaluation of type checking in CASE in SQL functions including subqueries no longer works in 18
Previous Message Heikki Linnakangas 2026-03-11 16:00:42 Re: BUG #19427: TOAST Snapshot Assertion Failure