diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-07-05 14:14:42 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-07-05 14:14:42 -0400 |
commit | ba8f00eef6d6199b1d01f4b1eb6ed955dc4bd17e (patch) | |
tree | 593cb541bdd30d93c30a84c9841a25e20e203d4b /doc/src | |
parent | aaab3ee9c64129b5afb2c35e743fba322a052bff (diff) | |
download | postgresql-ba8f00eef6d6199b1d01f4b1eb6ed955dc4bd17e.tar.gz postgresql-ba8f00eef6d6199b1d01f4b1eb6ed955dc4bd17e.zip |
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
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/pltcl.sgml | 17 |
1 files changed, 13 insertions, 4 deletions
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(); <para> In <productname>PostgreSQL</productname>, 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 <structname>pg_proc</structname> 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, <productname>PostgreSQL</productname> 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. </para> + <para> + 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 <function>spi_exec</function> or a related command. + </para> + </sect1> </chapter> |