Re: BUG #18463: Possible bug in stored procedures with polymorphic OUT parameters
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Bille <andrewbille@gmail.com>
Cc: Dmitry Dolgov <9erthalion6@gmail.com>, drewk@cockroachlabs.com,
pgsql-bugs@lists.postgresql.org
Date: 2024-06-04T21:02:02Z
Lists: pgsql-bugs
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix failure with SQL-procedure polymorphic output arguments in v12.
- d88dcdf0fa5b 14.13 landed
- bb331af4aeb7 16.4 landed
- 9de0ff91a501 13.16 landed
- 751598263690 17.0 landed
- 5fe43d41db59 15.8 landed
- 4208f44c9469 12.20 landed
-
Fix handling of polymorphic output arguments for procedures.
- f535f350c1f9 17.0 landed
- e85f641b2b52 13.16 landed
- c40e78d239a8 15.8 landed
- 8e0e99972ad9 16.4 landed
- 70ffb27b2349 12.20 landed
- 525bd1620e9b 14.13 landed
Attachments
- check-procedure-polymorphic-out-args-v12.patch (text/x-diff) patch v12
Andrew Bille <andrewbille@gmail.com> writes:
> After 70ffb27b in REL_12 following script
> CREATE OR REPLACE PROCEDURE p(inout a anyelement, inout b anyelement)
> LANGUAGE SQL
> AS $$
> SELECT $1, 1;
> $$;
> CALL p(1.1, null);
> crash server with backtrace:
So the problem here is that in v12, check_sql_fn_retval() fails to
resolve the 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. What needs to happen is for check_sql_fn_retval to resolve
those types and then notice that the SELECT output doesn't match.
In v13 and later, this was fixed by 913bbd88d ("Improve the handling
of result type coercions in SQL functions"), which not only did the
polymorphism stuff correctly but would also insert a cast from int
to numeric to allow this case to succeed. I thought then, and still
think, that that was too big a behavior change to risk back-patching.
So the best we can hope for in v12 is that this example throws an
error cleanly.
Fortunately that doesn't seem too painful --- with a little bit of
local rejiggering, we can use get_call_result_type instead of
get_func_result_type, and that will resolve the arguments correctly.
So that leads me to the attached.
Even though there's no bug in >= v13, I'm slightly tempted to put
the new test cases into the later branches too. If we'd had a test
like this we'd have noticed the problem ...
regards, tom lane