@@ -316,13 +316,24 @@ int SPI_execute(const char * <parameter>command</parameter>, bool <parameter>rea
316316 <para>
317317 If <parameter>count</parameter> is zero then the command is executed
318318 for all rows that it applies to. If <parameter>count</parameter>
319- is greater than 0, then the number of rows for which the command
320- will be executed is restricted (much like a
321- <literal>LIMIT</literal> clause). For example:
319+ is greater than zero, then no more than <parameter>count</parameter> rows
320+ will be retrieved; execution stops when the count is reached, much like
321+ adding a <literal>LIMIT</literal> clause to the query. For example,
322+ <programlisting>
323+ SPI_execute("SELECT * FROM foo", true, 5);
324+ </programlisting>
325+ will retrieve at most 5 rows from the table. Note that such a limit
326+ is only effective when the command actually returns rows. For example,
322327<programlisting>
323328SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
324329</programlisting>
325- will allow at most 5 rows to be inserted into the table.
330+ inserts all rows from <structname>bar</>, ignoring the
331+ <parameter>count</parameter> parameter. However, with
332+ <programlisting>
333+ SPI_execute("INSERT INTO foo SELECT * FROM bar RETURNING *", false, 5);
334+ </programlisting>
335+ at most 5 rows would be inserted, since execution would stop after the
336+ fifth <literal>RETURNING</> result row is retrieved.
326337 </para>
327338
328339 <para>
@@ -331,7 +342,8 @@ SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
331342 whole string will be parsed and planned before execution begins.
332343 <function>SPI_execute</function> returns the
333344 result for the command executed last. The <parameter>count</parameter>
334- limit applies to each command separately, but it is not applied to
345+ limit applies to each command separately (even though only the last
346+ result will actually be returned). The limit is not applied to any
335347 hidden commands generated by rules.
336348 </para>
337349
@@ -432,7 +444,8 @@ typedef struct
432444 <term><literal>long <parameter>count</parameter></literal></term>
433445 <listitem>
434446 <para>
435- maximum number of rows to process or return
447+ maximum number of rows to return,
448+ or <literal>0</> for no limit
436449 </para>
437450 </listitem>
438451 </varlistentry>
@@ -608,15 +621,12 @@ typedef struct
608621 <title>Notes</title>
609622
610623 <para>
611- The functions <function>SPI_execute</function>,
612- <function>SPI_exec</function>,
613- <function>SPI_execute_plan</function>, and
614- <function>SPI_execp</function> change both
624+ All SPI query-execution functions set both
615625 <varname>SPI_processed</varname> and
616626 <varname>SPI_tuptable</varname> (just the pointer, not the contents
617627 of the structure). Save these two global variables into local
618628 procedure variables if you need to access the result table of
619- <function>SPI_execute</function> ora related function
629+ <function>SPI_execute</function> oranother query-execution function
620630 across later calls.
621631 </para>
622632 </refsect1>
@@ -671,7 +681,8 @@ int SPI_exec(const char * <parameter>command</parameter>, long <parameter>count<
671681 <term><literal>long <parameter>count</parameter></literal></term>
672682 <listitem>
673683 <para>
674- maximum number of rows to process or return
684+ maximum number of rows to return,
685+ or <literal>0</> for no limit
675686 </para>
676687 </listitem>
677688 </varlistentry>
@@ -808,7 +819,8 @@ int SPI_execute_with_args(const char *<parameter>command</parameter>,
808819 <term><literal>long <parameter>count</parameter></literal></term>
809820 <listitem>
810821 <para>
811- maximum number of rows to process or return
822+ maximum number of rows to return,
823+ or <literal>0</> for no limit
812824 </para>
813825 </listitem>
814826 </varlistentry>
@@ -1424,7 +1436,8 @@ int SPI_execute_plan(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>
14241436 <term><literal>long <parameter>count</parameter></literal></term>
14251437 <listitem>
14261438 <para>
1427- maximum number of rows to process or return
1439+ maximum number of rows to return,
1440+ or <literal>0</> for no limit
14281441 </para>
14291442 </listitem>
14301443 </varlistentry>
@@ -1541,7 +1554,8 @@ int SPI_execute_plan_with_paramlist(SPIPlanPtr <parameter>plan</parameter>,
15411554 <term><literal>long <parameter>count</parameter></literal></term>
15421555 <listitem>
15431556 <para>
1544- maximum number of rows to process or return
1557+ maximum number of rows to return,
1558+ or <literal>0</> for no limit
15451559 </para>
15461560 </listitem>
15471561 </varlistentry>
@@ -1641,7 +1655,8 @@ int SPI_execp(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>values<
16411655 <term><literal>long <parameter>count</parameter></literal></term>
16421656 <listitem>
16431657 <para>
1644- maximum number of rows to process or return
1658+ maximum number of rows to return,
1659+ or <literal>0</> for no limit
16451660 </para>
16461661 </listitem>
16471662 </varlistentry>