1- <!-- $PostgreSQL: pgsql/doc/src/sgml/spi.sgml,v 1.46 2006/08/12 20:05:54 tgl Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/spi.sgml,v 1.47 2006/08/27 23:47:57 tgl Exp $ -->
22
33<chapter id="spi">
44 <title>Server Programming Interface</title>
@@ -361,12 +361,16 @@ SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
361361
362362 <para>
363363 The actual number of rows for which the (last) command was executed
364- is returned in the global variable <varname>SPI_processed</varname>
365- (unless the return value of the function is
366- <symbol>SPI_OK_UTILITY</symbol>). If the return value of the
367- function is <symbol>SPI_OK_SELECT</symbol> then you may use the
364+ is returned in the global variable <varname>SPI_processed</varname>.
365+ If the return value of the function is <symbol>SPI_OK_SELECT</symbol>,
366+ <symbol>SPI_OK_INSERT_RETURNING</symbol>,
367+ <symbol>SPI_OK_DELETE_RETURNING</symbol>, or
368+ <symbol>SPI_OK_UPDATE_RETURNING</symbol>,
369+ then you may use the
368370 global pointer <literal>SPITupleTable *SPI_tuptable</literal> to
369- access the result rows.
371+ access the result rows. Some utility commands (such as
372+ <command>EXPLAIN</>) also return rowsets, and <literal>SPI_tuptable</>
373+ will contain the result in these cases too.
370374 </para>
371375
372376 <para>
@@ -459,19 +463,19 @@ typedef struct
459463 </varlistentry>
460464
461465 <varlistentry>
462- <term><symbol>SPI_OK_DELETE </symbol></term>
466+ <term><symbol>SPI_OK_INSERT </symbol></term>
463467 <listitem>
464468 <para>
465- ifa <command>DELETE </command> was executed
469+ ifan <command>INSERT </command> was executed
466470 </para>
467471 </listitem>
468472 </varlistentry>
469473
470474 <varlistentry>
471- <term><symbol>SPI_OK_INSERT </symbol></term>
475+ <term><symbol>SPI_OK_DELETE </symbol></term>
472476 <listitem>
473477 <para>
474- ifan <command>INSERT </command> was executed
478+ ifa <command>DELETE </command> was executed
475479 </para>
476480 </listitem>
477481 </varlistentry>
@@ -485,6 +489,33 @@ typedef struct
485489 </listitem>
486490 </varlistentry>
487491
492+ <varlistentry>
493+ <term><symbol>SPI_OK_INSERT_RETURNING</symbol></term>
494+ <listitem>
495+ <para>
496+ if an <command>INSERT RETURNING</command> was executed
497+ </para>
498+ </listitem>
499+ </varlistentry>
500+
501+ <varlistentry>
502+ <term><symbol>SPI_OK_DELETE_RETURNING</symbol></term>
503+ <listitem>
504+ <para>
505+ if a <command>DELETE RETURNING</command> was executed
506+ </para>
507+ </listitem>
508+ </varlistentry>
509+
510+ <varlistentry>
511+ <term><symbol>SPI_OK_UPDATE_RETURNING</symbol></term>
512+ <listitem>
513+ <para>
514+ if an <command>UPDATE RETURNING</command> was executed
515+ </para>
516+ </listitem>
517+ </varlistentry>
518+
488519 <varlistentry>
489520 <term><symbol>SPI_OK_UTILITY</symbol></term>
490521 <listitem>
@@ -2987,10 +3018,9 @@ execq(text *sql, int cnt)
29873018
29883019 proc = SPI_processed;
29893020 /*
2990- * If this is a SELECT and some rows were fetched,
2991- * then the rows are printed via elog(INFO).
3021+ * If some rows were fetched, print them via elog(INFO).
29923022 */
2993- if (ret== SPI_OK_SELECT && SPI_processed > 0 )
3023+ if (ret> 0 && SPI_tuptable != NULL )
29943024 {
29953025 TupleDesc tupdesc = SPI_tuptable->tupdesc;
29963026 SPITupleTable *tuptable = SPI_tuptable;
@@ -3005,7 +3035,7 @@ execq(text *sql, int cnt)
30053035 snprintf(buf + strlen (buf), sizeof(buf) - strlen(buf), " %s%s",
30063036 SPI_getvalue(tuple, tupdesc, i),
30073037 (i == tupdesc->natts) ? " " : " |");
3008- elog (INFO, "EXECQ: %s", buf);
3038+ elog(INFO, "EXECQ: %s", buf);
30093039 }
30103040 }
30113041