<varlistentry>
<term><symbol>SPI_OPT_NONATOMIC</symbol></term>
<listitem>
<para>
Sets the SPI connection to be <firstterm>nonatomic</firstterm>, which
means that transaction control calls (<function>SPI_commit</function>,
<function>SPI_rollback</function>) are allowed. Otherwise,
calling those functions will result in an immediate error.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
<literal>SPI_connect()</literal> is equivalent to
<literal>SPI_connect_ext(0)</literal>.
</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<variablelist>
<varlistentry>
<term><symbol>SPI_OK_CONNECT</symbol></term>
<listitem>
<para>
on success
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
The fact that these functions return <type>int</type>
not <type>void</type> is historical. All failure cases are reported
via <function>ereport</function> or <function>elog</function>.
(In versions before <productname>PostgreSQL</productname> v10,
some but not all failures would be reported with a result value
of <symbol>SPI_ERROR_CONNECT</symbol>.)
</para>
</refsect1>
</refentry>
<!-- *********************************************** -->
<refentry id="spi-spi-finish">
<indexterm><primary>SPI_finish</primary></indexterm>
<refmeta>
<refentrytitle>SPI_finish</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>
<refnamediv>
<refname>SPI_finish</refname>
<refpurpose>disconnect a C function from the SPI manager</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
int SPI_finish(void)
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<function>SPI_finish</function> closes an existing connection to
the SPI manager. You must call this function after completing the
SPI operations needed during your C function's current invocation.
You do not need to worry about making this happen, however, if you
abort the transaction via <literal>elog(ERROR)</literal>. In that
case SPI will clean itself up automatically.
</para>
</refsect1>
<refsect1>
<title>Return Value</title>
<variablelist>
<varlistentry>
<term><symbol>SPI_OK_FINISH</symbol></term>
<listitem>
<para>
if properly disconnected
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><symbol>SPI_ERROR_UNCONNECTED</symbol></term>
<listitem>
<para>
if called from an unconnected C function
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
</refentry>
<!-- *********************************************** -->
<refentry id="spi-spi-execute">
<indexterm><primary>SPI_execute</primary></indexterm>
<refmeta>
<refentrytitle>SPI_execute</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>
<refnamediv>
<refname>SPI_execute</refname>
<refpurpose>execute a command</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
int SPI_execute(const char * <parameter>command</parameter>, bool <parameter>read_only</parameter>, long <parameter>count</parameter>)
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<function>SPI_execute</function> executes the specified SQL command
for <parameter>count</parameter> rows. If <parameter>read_only</parameter>
is <literal>true</literal>, the command must be read-only, and execution overhead
is somewhat reduced.
</para>
<para>
This function can only be called from a connected C function.
</para>
<para>
If <parameter>count</parameter> is zero then the command is executed
for all rows that it applies to. If <parameter>count</parameter>
is greater than zero, then no more than <parameter>count</parameter> rows
will be retrieved; execution stops when the count is reached, much like
adding a <literal>LIMIT</literal> clause to the query. For example,
<programlisting>
SPI_execute("SELECT