pplan = SPI_prepare(sql, nkeys, argtypes);
if (pplan == NULL)
/* internal error */
- elog(ERROR, "check_primary_key: SPI_prepare returned %d", SPI_result);
+ elog(ERROR, "check_primary_key: SPI_prepare returned %s", SPI_result_code_string(SPI_result));
/*
* Remember that SPI_prepare places plan in current memory context -
/* this shouldn't happen! SPI_ERROR_NOOUTFUNC ? */
if (oldval == NULL)
/* internal error */
- elog(ERROR, "check_foreign_key: SPI_getvalue returned %d", SPI_result);
+ elog(ERROR, "check_foreign_key: SPI_getvalue returned %s", SPI_result_code_string(SPI_result));
newval = SPI_getvalue(newtuple, tupdesc, fnumber);
if (newval == NULL || strcmp(oldval, newval) != 0)
isequal = false;
pplan = SPI_prepare(sql, nkeys, argtypes);
if (pplan == NULL)
/* internal error */
- elog(ERROR, "check_foreign_key: SPI_prepare returned %d", SPI_result);
+ elog(ERROR, "check_foreign_key: SPI_prepare returned %s", SPI_result_code_string(SPI_result));
/*
* Remember that SPI_prepare places plan in current memory context
/* Prepare plan for query */
pplan = SPI_prepare(sql, natts, ctypes);
if (pplan == NULL)
- elog(ERROR, "timetravel (%s): SPI_prepare returned %d", relname, SPI_result);
+ elog(ERROR, "timetravel (%s): SPI_prepare returned %s", relname, SPI_result_code_string(SPI_result));
/*
* Remember that SPI_prepare places plan in current memory context -
</refsect1>
</refentry>
+<refentry id="spi-spi-result-code-string">
+ <indexterm><primary>SPI_result_code_string</primary></indexterm>
+
+ <refmeta>
+ <refentrytitle>SPI_result_code_string</refentrytitle>
+ <manvolnum>3</manvolnum>
+ </refmeta>
+
+ <refnamediv>
+ <refname>SPI_result_code_string</refname>
+ <refpurpose>return error code as string</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+<synopsis>
+const char * SPI_result_code_string(int <parameter>code</parameter>);
+</synopsis>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+
+ <para>
+ <function>SPI_result_code_string</function> returns a string representation
+ of the result code returned by various SPI functions or stored
+ in <varname>SPI_result</varname>.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Arguments</title>
+
+ <variablelist>
+ <varlistentry>
+ <term><literal>int <parameter>code</parameter></literal></term>
+ <listitem>
+ <para>
+ result code
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>Return Value</title>
+
+ <para>
+ A string representation of the result code.
+ </para>
+ </refsect1>
+</refentry>
+
</sect1>
<sect1 id="spi-memory">
qplan = SPI_prepare(querybuf.data, 0, NULL);
if (qplan == NULL)
- elog(ERROR, "SPI_prepare returned %d for %s",
- SPI_result, querybuf.data);
+ elog(ERROR, "SPI_prepare returned %s for %s",
+ SPI_result_code_string(SPI_result), querybuf.data);
/*
* Run the plan. For safety we force a current snapshot to be used. (In
/* Check result */
if (spi_result != SPI_OK_SELECT)
- elog(ERROR, "SPI_execute_snapshot returned %d", spi_result);
+ elog(ERROR, "SPI_execute_snapshot returned %s", SPI_result_code_string(spi_result));
/* Did we find a tuple violating the constraint? */
if (SPI_processed > 0)
qplan = SPI_prepare(querystr, nargs, argtypes);
if (qplan == NULL)
- elog(ERROR, "SPI_prepare returned %d for %s", SPI_result, querystr);
+ elog(ERROR, "SPI_prepare returned %s for %s", SPI_result_code_string(SPI_result), querystr);
/* Restore UID and security context */
SetUserIdAndSecContext(save_userid, save_sec_context);
/* Check result */
if (spi_result < 0)
- elog(ERROR, "SPI_execute_snapshot returned %d", spi_result);
+ elog(ERROR, "SPI_execute_snapshot returned %s", SPI_result_code_string(spi_result));
if (expect_OK >= 0 && spi_result != expect_OK)
ereport(ERROR,
/* Prepare plan for query */
pplan = SPI_prepare(query, natts, ctypes);
if (pplan == NULL)
- elog(ERROR, "ttdummy (%s): SPI_prepare returned %d", relname, SPI_result);
+ elog(ERROR, "ttdummy (%s): SPI_prepare returned %s", relname, SPI_result_code_string(SPI_result));
if (SPI_keepplan(pplan))
elog(ERROR, "ttdummy (%s): SPI_keepplan failed", relname);