From d42dbe0d80ab49b0dc2deab772f08e9b334df544 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Mon, 5 Oct 2026 11:38:02 -0400 Subject: [PATCH v1 2/2] plpgsql: test SELECT INTO after a function becomes set-returning The existing test for a non-SRF replaced by a SRF only covers assignment. Add the SELECT INTO form, where the first call after the change must not report FOUND for zero rows. --- .../plpgsql/src/expected/plpgsql_simple.out | 37 +++++++++++++++++++ src/pl/plpgsql/src/sql/plpgsql_simple.sql | 28 ++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/src/pl/plpgsql/src/expected/plpgsql_simple.out b/src/pl/plpgsql/src/expected/plpgsql_simple.out index ccf15ea2200..c9d924177d9 100644 --- a/src/pl/plpgsql/src/expected/plpgsql_simple.out +++ b/src/pl/plpgsql/src/expected/plpgsql_simple.out @@ -118,6 +118,43 @@ select simplecaller(); 44 (1 row) +-- Same for "SELECT simple-expr INTO var": the SRF returns no rows, so +-- FOUND must be false on the first call after the change too +drop function simplesql(); +create function simplesql() returns int language sql +as $$select 2 + 2$$; +create or replace function simplecaller() returns int language plpgsql +as $$ +declare x int; +begin + select simplesql() into x; + raise notice 'found = %', found; + return x; +end$$; +select simplecaller(); +NOTICE: found = t + simplecaller +-------------- + 4 +(1 row) + +drop function simplesql(); +create function simplesql() returns setof int language sql +as $$select 22 + 22 where false$$; +select simplecaller(); +NOTICE: found = f + simplecaller +-------------- + +(1 row) + +select simplecaller(); +NOTICE: found = f + simplecaller +-------------- + +(1 row) + -- Check handling of simple expression in a scrollable cursor (bug #18859) do $$ declare diff --git a/src/pl/plpgsql/src/sql/plpgsql_simple.sql b/src/pl/plpgsql/src/sql/plpgsql_simple.sql index d64e791800b..36f1b3274ff 100644 --- a/src/pl/plpgsql/src/sql/plpgsql_simple.sql +++ b/src/pl/plpgsql/src/sql/plpgsql_simple.sql @@ -103,6 +103,34 @@ select simplecaller(); select simplecaller(); +-- Same for "SELECT simple-expr INTO var": the SRF returns no rows, so +-- FOUND must be false on the first call after the change too + +drop function simplesql(); + +create function simplesql() returns int language sql +as $$select 2 + 2$$; + +create or replace function simplecaller() returns int language plpgsql +as $$ +declare x int; +begin + select simplesql() into x; + raise notice 'found = %', found; + return x; +end$$; + +select simplecaller(); + +drop function simplesql(); + +create function simplesql() returns setof int language sql +as $$select 22 + 22 where false$$; + +select simplecaller(); + +select simplecaller(); + -- Check handling of simple expression in a scrollable cursor (bug #18859) do $$ -- 2.37.1 (Apple Git-137.1)