mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Follow-on cleanup for the transition table patch.
Commit 59702716
added transition table support to PL/pgsql so that
SQL queries in trigger functions could access those transient
tables. In order to provide the same level of support for PL/perl,
PL/python and PL/tcl, refactor the relevant code into a new
function SPI_register_trigger_data. Call the new function in the
trigger handler of all four PLs, and document it as a public SPI
function so that authors of out-of-tree PLs can do the same.
Also get rid of a second QueryEnvironment object that was
maintained by PL/pgsql. That was previously used to deal with
cursors, but the same approach wasn't appropriate for PLs that are
less tangled up with core code. Instead, have SPI_cursor_open
install the connection's current QueryEnvironment, as already
happens for SPI_execute_plan.
While in the docs, remove the note that transition tables were only
supported in C and PL/pgSQL triggers, and correct some ommissions.
Thomas Munro with some work by Kevin Grittner (mostly docs)
This commit is contained in:
@@ -395,6 +395,11 @@
|
||||
<secondary>in C</secondary>
|
||||
</indexterm>
|
||||
|
||||
<indexterm>
|
||||
<primary>transition tables</primary>
|
||||
<secondary>referencing from C trigger</secondary>
|
||||
</indexterm>
|
||||
|
||||
<para>
|
||||
This section describes the low-level details of the interface to a
|
||||
trigger function. This information is only needed when writing
|
||||
@@ -438,14 +443,16 @@ CALLED_AS_TRIGGER(fcinfo)
|
||||
<programlisting>
|
||||
typedef struct TriggerData
|
||||
{
|
||||
NodeTag type;
|
||||
TriggerEvent tg_event;
|
||||
Relation tg_relation;
|
||||
HeapTuple tg_trigtuple;
|
||||
HeapTuple tg_newtuple;
|
||||
Trigger *tg_trigger;
|
||||
Buffer tg_trigtuplebuf;
|
||||
Buffer tg_newtuplebuf;
|
||||
NodeTag type;
|
||||
TriggerEvent tg_event;
|
||||
Relation tg_relation;
|
||||
HeapTuple tg_trigtuple;
|
||||
HeapTuple tg_newtuple;
|
||||
Trigger *tg_trigger;
|
||||
Buffer tg_trigtuplebuf;
|
||||
Buffer tg_newtuplebuf;
|
||||
Tuplestorestate *tg_oldtable;
|
||||
Tuplestorestate *tg_newtable;
|
||||
} TriggerData;
|
||||
</programlisting>
|
||||
|
||||
@@ -629,6 +636,8 @@ typedef struct Trigger
|
||||
int16 *tgattr;
|
||||
char **tgargs;
|
||||
char *tgqual;
|
||||
char *tgoldtable;
|
||||
char *tgnewtable;
|
||||
} Trigger;
|
||||
</programlisting>
|
||||
|
||||
@@ -662,9 +671,38 @@ typedef struct Trigger
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><structfield>tg_oldtable</></term>
|
||||
<listitem>
|
||||
<para>
|
||||
A pointer to a structure of type <structname>Tuplestorestate</structname>
|
||||
containing zero or more rows in the format specified by
|
||||
<structfield>tg_relation</structfield>, or a <symbol>NULL</> pointer
|
||||
if there is no <literal>OLD TABLE</literal> transition relation.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><structfield>tg_newtable</></term>
|
||||
<listitem>
|
||||
<para>
|
||||
A pointer to a structure of type <structname>Tuplestorestate</structname>
|
||||
containing zero or more rows in the format specified by
|
||||
<structfield>tg_relation</structfield>, or a <symbol>NULL</> pointer
|
||||
if there is no <literal>NEW TABLE</literal> transition relation.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
To allow queries issued through SPI to reference transition tables, see
|
||||
<xref linkend="spi-spi-register-trigger-data">.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
A trigger function must return either a
|
||||
<structname>HeapTuple</> pointer or a <symbol>NULL</> pointer
|
||||
|
Reference in New Issue
Block a user