Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7515982

Browse files
committed
Fix failure with SQL-procedure polymorphic output arguments in v12.
Before the v13-era commit 913bbd8, 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 913bbd8, 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 70ffb27, 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
1 parent e6cd857 commit 7515982

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/test/regress/expected/create_procedure.out

+17
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,23 @@ CALL ptest6b(1.1, null, null);
227227
1.1 | {1.1}
228228
(1 row)
229229

230+
CREATE PROCEDURE ptest6c(inout a anyelement, inout b anyelement)
231+
LANGUAGE SQL
232+
AS $$
233+
SELECT $1, 1;
234+
$$;
235+
CALL ptest6c(1, null);
236+
a | b
237+
---+---
238+
1 | 1
239+
(1 row)
240+
241+
CALL ptest6c(1.1, null); -- fails before v13
242+
a | b
243+
-----+---
244+
1.1 | 1
245+
(1 row)
246+
230247
-- collation assignment
231248
CREATE PROCEDURE ptest7(a text, b text)
232249
LANGUAGE SQL

src/test/regress/sql/create_procedure.sql

+9
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ $$;
149149
CALL ptest6b(1, null, null);
150150
CALL ptest6b(1.1, null, null);
151151

152+
CREATE PROCEDURE ptest6c(inout a anyelement, inout b anyelement)
153+
LANGUAGE SQL
154+
AS $$
155+
SELECT $1, 1;
156+
$$;
157+
158+
CALL ptest6c(1, null);
159+
CALL ptest6c(1.1, null); -- fails before v13
160+
152161

153162
-- collation assignment
154163

0 commit comments

Comments
 (0)