postgres.git / summary / log / commit / refs
commit 7c19a14bbef39c58cb0029b95449e583822a182c
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Wed Nov 18 14:53:15 2026 +0000
Don't create a shell type for a function returning SETOF
Commit 2866d8c7db tightened the rules for when CREATE FUNCTION creates
a shell type. Tighten some more, to not create a shell type for
functions returning SETOF either, for similar reasons. Backpatch to
all supported versions, like commit 2866d8c7db (v14 is no longer
supported however).
Author: Ewan Young <kdbase.hack@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAON2xHN8y=9KeFnEb4KAKPvVks5VQaMUFJSGTv3T9VY777EKRw@mail.gmail.com
Backpatch-through: 15
src/backend/commands/functioncmds.c | 3 ++-
src/test/regress/expected/create_type.out | 6 ++++++
src/test/regress/sql/create_type.sql | 6 ++++++
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 0c938372cbd..ac093fcd8f4 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -100,6 +100,7 @@ compute_return_type(TypeName *returnType, Oid languageOid,
* If the type name contains any modifiers like %TYPE, type[] array
* syntax, or typmod decoration, it's not an input function, or at least
* not one for which we'd want to automatically create a shell type.
+ * Likewise, an input function never returns a set.
*
* Only C-coded functions can be I/O functions. We enforce this
* restriction here mainly to prevent littering the catalogs with shell
@@ -107,7 +108,7 @@ compute_return_type(TypeName *returnType, Oid languageOid,
*/
attempt_shell_creation =
!returnType->pct_type && returnType->arrayBounds == NULL &&
- returnType->typmods == NIL &&
+ returnType->typmods == NIL && !returnType->setof &&
(languageOid == INTERNALlanguageId || languageOid == ClanguageId);
typtup = LookupTypeName(NULL, returnType, NULL, false);
diff --git a/src/test/regress/expected/create_type.out b/src/test/regress/expected/create_type.out
index 09cfa8da22c..704e9b5e39c 100644
--- a/src/test/regress/expected/create_type.out
+++ b/src/test/regress/expected/create_type.out
@@ -62,6 +62,12 @@ CREATE FUNCTION bogus_in(cstring)
AS :'regresslib', 'widget_in'
LANGUAGE C STRICT IMMUTABLE;
ERROR: type "bogus_shell[]" does not exist
+-- Likewise, if the function returns a set, don't create a shell type
+CREATE FUNCTION bogus_in(cstring)
+ RETURNS SETOF bogus_shell
+ AS :'regresslib', 'widget_in'
+ LANGUAGE C STRICT IMMUTABLE;
+ERROR: type "bogus_shell" does not exist
-- If the column specified with %TYPE does not exist, don't try to create a shell type
CREATE TEMP TABLE bogus_tbl (col int);
CREATE FUNCTION bogus_in(cstring)
diff --git a/src/test/regress/sql/create_type.sql b/src/test/regress/sql/create_type.sql
index 4fd1facdffe..4d73cee5cb0 100644
--- a/src/test/regress/sql/create_type.sql
+++ b/src/test/regress/sql/create_type.sql
@@ -62,6 +62,12 @@ CREATE FUNCTION bogus_in(cstring)
AS :'regresslib', 'widget_in'
LANGUAGE C STRICT IMMUTABLE;
+-- Likewise, if the function returns a set, don't create a shell type
+CREATE FUNCTION bogus_in(cstring)
+ RETURNS SETOF bogus_shell
+ AS :'regresslib', 'widget_in'
+ LANGUAGE C STRICT IMMUTABLE;
+
-- If the column specified with %TYPE does not exist, don't try to create a shell type
CREATE TEMP TABLE bogus_tbl (col int);
CREATE FUNCTION bogus_in(cstring)
[parent: f1579ff53e18]