From ba8f00eef6d6199b1d01f4b1eb6ed955dc4bd17e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 5 Jul 2024 14:14:42 -0400 Subject: Improve PL/Tcl's method for choosing Tcl names of procedures. Previously, the internal name of a PL/Tcl function was just "__PLTcl_proc_NNNN", where NNNN is the function OID. That's pretty unhelpful when reading an error report. Plus it prevents us from testing the CONTEXT output for PL/Tcl errors, since the OIDs shown in the regression tests wouldn't be stable. Instead, base the internal name on the result of format_procedure(), which will be unique in most cases. For the edge cases where it's not, we can append the function OID to make it unique. Sadly, the pltcl_trigger.sql test script still has to suppress the context reports, because they'd include trigger arguments which contain relation OIDs per PL/Tcl's longstanding API for triggers. I had to modify one existing test case to throw a different error than before, because I found that Tcl 8.5 and Tcl 8.6 spell the context message for the original error slightly differently. We might have to make more adjustments in that vein once this gets wider testing. Patch by me; thanks to Pavel Stehule for the idea to use format_procedure() rather than just the proname. Discussion: https://postgr.es/m/890581.1717609350@sss.pgh.pa.us --- doc/src/sgml/pltcl.sgml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/pltcl.sgml b/doc/src/sgml/pltcl.sgml index b31f2c1330f..5a8e4c9d37e 100644 --- a/doc/src/sgml/pltcl.sgml +++ b/doc/src/sgml/pltcl.sgml @@ -1120,16 +1120,25 @@ CALL transaction_test1(); In PostgreSQL, the same function name can be used for - different function definitions as long as the number of arguments or their types + different function definitions if the functions are placed in different + schemas, or if the number of arguments or their types differ. Tcl, however, requires all procedure names to be distinct. - PL/Tcl deals with this by making the internal Tcl procedure names contain - the object - ID of the function from the system table pg_proc as part of their name. Thus, + PL/Tcl deals with this by including the argument type names in the + internal Tcl procedure name, and then appending the function's object + ID (OID) to the internal Tcl procedure name if necessary to make it + different from the names of all previously-loaded functions in the + same Tcl interpreter. Thus, PostgreSQL functions with the same name and different argument types will be different Tcl procedures, too. This is not normally a concern for a PL/Tcl programmer, but it might be visible when debugging. + + For this reason among others, a PL/Tcl function cannot call another one + directly (that is, within Tcl). If you need to do that, you must go + through SQL, using spi_exec or a related command. + + -- cgit v1.2.3