1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

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
This commit is contained in:
Tom Lane
2024-07-05 14:14:42 -04:00
parent aaab3ee9c6
commit ba8f00eef6
8 changed files with 520 additions and 46 deletions

View File

@@ -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>