mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Add infrastructure to support EphemeralNamedRelation references.
A QueryEnvironment concept is added, which allows new types of objects to be passed into queries from parsing on through execution. At this point, the only thing implemented is a collection of EphemeralNamedRelation objects -- relations which can be referenced by name in queries, but do not exist in the catalogs. The only type of ENR implemented is NamedTuplestore, but provision is made to add more types fairly easily. An ENR can carry its own TupleDesc or reference a relation in the catalogs by relid. Although these features can be used without SPI, convenience functions are added to SPI so that ENRs can easily be used by code run through SPI. The initial use of all this is going to be transition tables in AFTER triggers, but that will be added to each PL as a separate commit. An incidental effect of this patch is to produce a more informative error message if an attempt is made to modify the contents of a CTE from a referencing DML statement. No tests previously covered that possibility, so one is added. Kevin Grittner and Thomas Munro Reviewed by Heikki Linnakangas, David Fetter, and Thomas Munro with valuable comments and suggestions from many others
This commit is contained in:
@ -2639,6 +2639,210 @@ SPIPlanPtr SPI_saveplan(SPIPlanPtr <parameter>plan</parameter>)
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<!-- *********************************************** -->
|
||||
|
||||
<refentry id="spi-spi-register-relation">
|
||||
<indexterm><primary>SPI_register_relation</primary></indexterm>
|
||||
|
||||
<refmeta>
|
||||
<refentrytitle>SPI_register_relation</refentrytitle>
|
||||
<manvolnum>3</manvolnum>
|
||||
</refmeta>
|
||||
|
||||
<refnamediv>
|
||||
<refname>SPI_register_relation</refname>
|
||||
<refpurpose>make a ephemeral named relation available by name in SPI queries</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<synopsis>
|
||||
int SPI_register_relation(EphemeralNamedRelation <parameter>enr</parameter>)
|
||||
</synopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
||||
<para>
|
||||
<function>SPI_register_relation</function> makes an ephemeral named
|
||||
relation, with associated information, available to queries planned and
|
||||
executed through the current SPI connection.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Arguments</title>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><literal>EphemeralNamedRelation <parameter>enr</parameter></literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
the ephemeral named relation registry entry
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Return Value</title>
|
||||
|
||||
<para>
|
||||
If the execution of the command was successful then the following
|
||||
(nonnegative) value will be returned:
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><symbol>SPI_OK_REL_REGISTER</symbol></term>
|
||||
<listitem>
|
||||
<para>
|
||||
if the relation has been successfully registered by name
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
On error, one of the following negative values is returned:
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><symbol>SPI_ERROR_ARGUMENT</symbol></term>
|
||||
<listitem>
|
||||
<para>
|
||||
if <parameter>enr</parameter> is <symbol>NULL</symbol> or its
|
||||
<varname>name</varname> field is <symbol>NULL</symbol>
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><symbol>SPI_ERROR_UNCONNECTED</symbol></term>
|
||||
<listitem>
|
||||
<para>
|
||||
if called from an unconnected procedure
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><symbol>SPI_ERROR_REL_DUPLICATE</symbol></term>
|
||||
<listitem>
|
||||
<para>
|
||||
if the name specified in the <varname>name</varname> field of
|
||||
<parameter>enr</parameter> is already registered for this connection
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<!-- *********************************************** -->
|
||||
|
||||
<refentry id="spi-spi-unregister-relation">
|
||||
<indexterm><primary>SPI_unregister_relation</primary></indexterm>
|
||||
|
||||
<refmeta>
|
||||
<refentrytitle>SPI_unregister_relation</refentrytitle>
|
||||
<manvolnum>3</manvolnum>
|
||||
</refmeta>
|
||||
|
||||
<refnamediv>
|
||||
<refname>SPI_unregister_relation</refname>
|
||||
<refpurpose>remove an ephemeral named relation from the registry</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsynopsisdiv>
|
||||
<synopsis>
|
||||
int SPI_unregister_relation(const char * <parameter>name</parameter>)
|
||||
</synopsis>
|
||||
</refsynopsisdiv>
|
||||
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
||||
<para>
|
||||
<function>SPI_unregister_relation</function> removes an ephemeral named
|
||||
relation from the registry for the current connection.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Arguments</title>
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><literal>const char * <parameter>name</parameter></literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
the relation registry entry name
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
<title>Return Value</title>
|
||||
|
||||
<para>
|
||||
If the execution of the command was successful then the following
|
||||
(nonnegative) value will be returned:
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><symbol>SPI_OK_REL_UNREGISTER</symbol></term>
|
||||
<listitem>
|
||||
<para>
|
||||
if the tuplestore has been successfully removed from the registry
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
On error, one of the following negative values is returned:
|
||||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><symbol>SPI_ERROR_ARGUMENT</symbol></term>
|
||||
<listitem>
|
||||
<para>
|
||||
if <parameter>name</parameter> is <symbol>NULL</symbol>
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><symbol>SPI_ERROR_UNCONNECTED</symbol></term>
|
||||
<listitem>
|
||||
<para>
|
||||
if called from an unconnected procedure
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><symbol>SPI_ERROR_REL_NOT_FOUND</symbol></term>
|
||||
<listitem>
|
||||
<para>
|
||||
if <parameter>name</parameter> is not found in the registry for the
|
||||
current connection
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<!-- *********************************************** -->
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1 id="spi-interface-support">
|
||||
|
Reference in New Issue
Block a user