Fix failure with SQL-procedure polymorphic output arguments in v12.
authorTom Lane <[email protected]>
Thu, 6 Jun 2024 19:16:56 +0000 (15:16 -0400)
committerTom Lane <[email protected]>
Thu, 6 Jun 2024 19:16:56 +0000 (15:16 -0400)
Before the v13-era commit 913bbd88d, check_sql_fn_retval fails to
resolve polymorphic output types and then just throws up its hands and
assumes the check will be made at runtime.  I think that's true for
ordinary functions returning RECORD, but it doesn't happen in CALL,
potentially resulting in crashes if the actual output of the SQL
procedure's SELECT doesn't match the type inferred from polymorphism.
With a little bit of rearrangement, we can use get_call_result_type
instead of get_func_result_type and thereby infer the correct types.

I'm still unwilling to back-patch all of 913bbd88d, so if the types
don't match you'll get an error rather than perhaps silently inserting
a cast as v13 and later can.  That's consistent with prior behavior
though, so it seems fine.

Prior to 70ffb27b2, you'd typically get other errors due to other
shortcomings of CALL's management of polymorphism.  Nonetheless,
this is an independent bug.

Although there is no bug in v13 and up, it seems prudent to add
the test case for this to the newer branches too.  It's clearly
an under-tested area.

Per report from Andrew Bille.

Discussion: https://postgr.es/m/CAJnzarw9EeWHAQRm76dXd=7j+rgw6ERqC=nCay8jeFqTwKwhqQ@mail.gmail.com

src/test/regress/expected/create_procedure.out
src/test/regress/sql/create_procedure.sql

index 8bf5f9a362a2a784f1085392c8d42ea23c672f4a..55e30a3409f605b278e78dbe148b561c4ff7b7fc 100644 (file)
@@ -185,6 +185,23 @@ CALL ptest6b(1.1, null, null);
  1.1 | {1.1}
 (1 row)
 
+CREATE PROCEDURE ptest6c(inout a anyelement, inout b anyelement)
+LANGUAGE SQL
+AS $$
+SELECT $1, 1;
+$$;
+CALL ptest6c(1, null);
+ a | b 
+---+---
+ 1 | 1
+(1 row)
+
+CALL ptest6c(1.1, null);  -- fails before v13
+  a  | b 
+-----+---
+ 1.1 | 1
+(1 row)
+
 -- collation assignment
 CREATE PROCEDURE ptest7(a text, b text)
 LANGUAGE SQL
index ec32656c1538a67fe9f885cf72089cb81817003e..e43fed0d6f71aebc6ca364a9ee557cb5f6c37017 100644 (file)
@@ -127,6 +127,15 @@ $$;
 CALL ptest6b(1, null, null);
 CALL ptest6b(1.1, null, null);
 
+CREATE PROCEDURE ptest6c(inout a anyelement, inout b anyelement)
+LANGUAGE SQL
+AS $$
+SELECT $1, 1;
+$$;
+
+CALL ptest6c(1, null);
+CALL ptest6c(1.1, null);  -- fails before v13
+
 
 -- collation assignment