From 6121539aca2c797b8a9a78bb642ed060a9209d8e Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Thu, 24 Jan 2013 18:34:15 -0500
Subject: Fix SPI documentation for new handling of ExecutorRun's count
parameter.
Since 9.0, the count parameter has only limited the number of tuples
actually returned by the executor. It doesn't affect the behavior of
INSERT/UPDATE/DELETE unless RETURNING is specified, because without
RETURNING, the ModifyTable plan node doesn't return control to execMain.c
for each tuple. And we only check the limit at the top level.
While this behavioral change was unintentional at the time, discussion of
bug #6572 led us to the conclusion that we prefer the new behavior anyway,
and so we should just adjust the docs to match rather than change the code.
Accordingly, do that. Back-patch as far as 9.0 so that the docs match the
code in each branch.
---
doc/src/sgml/spi.sgml | 47 +++++++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 16 deletions(-)
(limited to 'doc/src')
diff --git a/doc/src/sgml/spi.sgml b/doc/src/sgml/spi.sgml
index 033e2249096..2d0a4addbfd 100644
--- a/doc/src/sgml/spi.sgml
+++ b/doc/src/sgml/spi.sgml
@@ -316,13 +316,24 @@ int SPI_execute(const char * command, bool rea
If count is zero then the command is executed
for all rows that it applies to. If count
- is greater than 0, then the number of rows for which the command
- will be executed is restricted (much like a
- LIMIT clause). For example:
+ is greater than zero, then no more than count rows
+ will be retrieved; execution stops when the count is reached, much like
+ adding a LIMIT clause to the query. For example,
+
+SPI_execute("SELECT * FROM foo", true, 5);
+
+ will retrieve at most 5 rows from the table. Note that such a limit
+ is only effective when the command actually returns rows. For example,
SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
- will allow at most 5 rows to be inserted into the table.
+ inserts all rows from bar>, ignoring the
+ count parameter. However, with
+
+SPI_execute("INSERT INTO foo SELECT * FROM bar RETURNING *", false, 5);
+
+ at most 5 rows would be inserted, since execution would stop after the
+ fifth RETURNING> result row is retrieved.
@@ -331,7 +342,8 @@ SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
whole string will be parsed and planned before execution begins.
SPI_execute returns the
result for the command executed last. The count
- limit applies to each command separately, but it is not applied to
+ limit applies to each command separately (even though only the last
+ result will actually be returned). The limit is not applied to any
hidden commands generated by rules.
@@ -435,7 +447,8 @@ typedef struct
long count
- maximum number of rows to process or return
+ maximum number of rows to return,
+ or 0> for no limit
@@ -611,15 +624,12 @@ typedef struct
Notes
- The functions SPI_execute,
- SPI_exec,
- SPI_execute_plan, and
- SPI_execp change both
+ All SPI query-execution functions set both
SPI_processed and
SPI_tuptable (just the pointer, not the contents
of the structure). Save these two global variables into local
procedure variables if you need to access the result table of
- SPI_execute or a related function
+ SPI_execute or another query-execution function
across later calls.
@@ -674,7 +684,8 @@ int SPI_exec(const char * command, long count<
long count
- maximum number of rows to process or return
+ maximum number of rows to return,
+ or 0> for no limit
@@ -813,7 +824,8 @@ int SPI_execute_with_args(const char *command,
long count
- maximum number of rows to process or return
+ maximum number of rows to return,
+ or 0> for no limit
@@ -1431,7 +1443,8 @@ int SPI_execute_plan(SPIPlanPtr plan, Datum *
long count
- maximum number of rows to process or return
+ maximum number of rows to return,
+ or 0> for no limit
@@ -1550,7 +1563,8 @@ int SPI_execute_plan_with_paramlist(SPIPlanPtr plan,
long count
- maximum number of rows to process or return
+ maximum number of rows to return,
+ or 0> for no limit
@@ -1650,7 +1664,8 @@ int SPI_execp(SPIPlanPtr plan, Datum * values<
long count
- maximum number of rows to process or return
+ maximum number of rows to return,
+ or 0> for no limit
--
cgit v1.2.3