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 $ -->
2
2
3
3
<chapter id="spi">
4
4
<title>Server Programming Interface</title>
@@ -361,12 +361,16 @@ SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
361
361
362
362
<para>
363
363
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
368
370
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.
370
374
</para>
371
375
372
376
<para>
@@ -459,19 +463,19 @@ typedef struct
459
463
</varlistentry>
460
464
461
465
<varlistentry>
462
- <term><symbol>SPI_OK_DELETE </symbol></term>
466
+ <term><symbol>SPI_OK_INSERT </symbol></term>
463
467
<listitem>
464
468
<para>
465
- if a <command>DELETE </command> was executed
469
+ if an <command>INSERT </command> was executed
466
470
</para>
467
471
</listitem>
468
472
</varlistentry>
469
473
470
474
<varlistentry>
471
- <term><symbol>SPI_OK_INSERT </symbol></term>
475
+ <term><symbol>SPI_OK_DELETE </symbol></term>
472
476
<listitem>
473
477
<para>
474
- if an <command>INSERT </command> was executed
478
+ if a <command>DELETE </command> was executed
475
479
</para>
476
480
</listitem>
477
481
</varlistentry>
@@ -485,6 +489,33 @@ typedef struct
485
489
</listitem>
486
490
</varlistentry>
487
491
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
+
488
519
<varlistentry>
489
520
<term><symbol>SPI_OK_UTILITY</symbol></term>
490
521
<listitem>
@@ -2987,10 +3018,9 @@ execq(text *sql, int cnt)
2987
3018
2988
3019
proc = SPI_processed;
2989
3020
/*
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).
2992
3022
*/
2993
- if (ret == SPI_OK_SELECT && SPI_processed > 0 )
3023
+ if (ret > 0 && SPI_tuptable != NULL )
2994
3024
{
2995
3025
TupleDesc tupdesc = SPI_tuptable->tupdesc;
2996
3026
SPITupleTable *tuptable = SPI_tuptable;
@@ -3005,7 +3035,7 @@ execq(text *sql, int cnt)
3005
3035
snprintf(buf + strlen (buf), sizeof(buf) - strlen(buf), " %s%s",
3006
3036
SPI_getvalue(tuple, tupdesc, i),
3007
3037
(i == tupdesc->natts) ? " " : " |");
3008
- elog (INFO, "EXECQ: %s", buf);
3038
+ elog(INFO, "EXECQ: %s", buf);
3009
3039
}
3010
3040
}
3011
3041
0 commit comments