From ea2e263539df6a7df33e58e44236c504eb268e68 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 27 Aug 2006 23:47:58 +0000 Subject: Add new return codes SPI_OK_INSERT_RETURNING etc to the SPI API. Fix all the standard PLs to be able to return tuples from FOO_RETURNING statements as well as utility statements that return tuples. Also, fix oversight that SPI_processed wasn't set for a utility statement returning tuples. Per recent discussion. --- doc/src/sgml/spi.sgml | 58 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 14 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/spi.sgml b/doc/src/sgml/spi.sgml index 016874dce70..b19189632e6 100644 --- a/doc/src/sgml/spi.sgml +++ b/doc/src/sgml/spi.sgml @@ -1,4 +1,4 @@ - + Server Programming Interface @@ -361,12 +361,16 @@ SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5); The actual number of rows for which the (last) command was executed - is returned in the global variable SPI_processed - (unless the return value of the function is - SPI_OK_UTILITY). If the return value of the - function is SPI_OK_SELECT then you may use the + is returned in the global variable SPI_processed. + If the return value of the function is SPI_OK_SELECT, + SPI_OK_INSERT_RETURNING, + SPI_OK_DELETE_RETURNING, or + SPI_OK_UPDATE_RETURNING, + then you may use the global pointer SPITupleTable *SPI_tuptable to - access the result rows. + access the result rows. Some utility commands (such as + EXPLAIN) also return rowsets, and SPI_tuptable + will contain the result in these cases too. @@ -459,19 +463,19 @@ typedef struct - SPI_OK_DELETE + SPI_OK_INSERT - if a DELETE was executed + if an INSERT was executed - SPI_OK_INSERT + SPI_OK_DELETE - if an INSERT was executed + if a DELETE was executed @@ -485,6 +489,33 @@ typedef struct + + SPI_OK_INSERT_RETURNING + + + if an INSERT RETURNING was executed + + + + + + SPI_OK_DELETE_RETURNING + + + if a DELETE RETURNING was executed + + + + + + SPI_OK_UPDATE_RETURNING + + + if an UPDATE RETURNING was executed + + + + SPI_OK_UTILITY @@ -2987,10 +3018,9 @@ execq(text *sql, int cnt) proc = SPI_processed; /* - * If this is a SELECT and some rows were fetched, - * then the rows are printed via elog(INFO). + * If some rows were fetched, print them via elog(INFO). */ - if (ret == SPI_OK_SELECT && SPI_processed > 0) + if (ret > 0 && SPI_tuptable != NULL) { TupleDesc tupdesc = SPI_tuptable->tupdesc; SPITupleTable *tuptable = SPI_tuptable; @@ -3005,7 +3035,7 @@ execq(text *sql, int cnt) snprintf(buf + strlen (buf), sizeof(buf) - strlen(buf), " %s%s", SPI_getvalue(tuple, tupdesc, i), (i == tupdesc->natts) ? " " : " |"); - elog (INFO, "EXECQ: %s", buf); + elog(INFO, "EXECQ: %s", buf); } } -- cgit v1.2.3