@@ -316,20 +316,32 @@ 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>
329340 You can pass multiple commands in one string;
330341 <function>SPI_execute</function> returns the
331342 result for the command executed last. The <parameter>count</parameter>
332- limit applies to each command separately, but it is not applied to
343+ limit applies to each command separately (even though only the last
344+ result will actually be returned). The limit is not applied to any
333345 hidden commands generated by rules.
334346 </para>
335347
@@ -434,7 +446,7 @@ typedef struct
434446 <term><literal>long <parameter>count</parameter></literal></term>
435447 <listitem>
436448 <para>
437- maximum number of rows to process or return,
449+ maximum number of rows to return,
438450 or <literal>0</> for no limit
439451 </para>
440452 </listitem>
@@ -611,15 +623,12 @@ typedef struct
611623 <title>Notes</title>
612624
613625 <para>
614- The functions <function>SPI_execute</function>,
615- <function>SPI_exec</function>,
616- <function>SPI_execute_plan</function>, and
617- <function>SPI_execp</function> change both
626+ All SPI query-execution functions set both
618627 <varname>SPI_processed</varname> and
619628 <varname>SPI_tuptable</varname> (just the pointer, not the contents
620629 of the structure). Save these two global variables into local
621630 procedure variables if you need to access the result table of
622- <function>SPI_execute</function> or a related function
631+ <function>SPI_execute</function> or another query-execution function
623632 across later calls.
624633 </para>
625634 </refsect1>
@@ -674,7 +683,7 @@ int SPI_exec(const char * <parameter>command</parameter>, long <parameter>count<
674683 <term><literal>long <parameter>count</parameter></literal></term>
675684 <listitem>
676685 <para>
677- maximum number of rows to process or return,
686+ maximum number of rows to return,
678687 or <literal>0</> for no limit
679688 </para>
680689 </listitem>
@@ -813,7 +822,7 @@ int SPI_execute_with_args(const char *<parameter>command</parameter>,
813822 <term><literal>long <parameter>count</parameter></literal></term>
814823 <listitem>
815824 <para>
816- maximum number of rows to process or return,
825+ maximum number of rows to return,
817826 or <literal>0</> for no limit
818827 </para>
819828 </listitem>
@@ -1457,7 +1466,7 @@ int SPI_execute_plan(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>
14571466 <term><literal>long <parameter>count</parameter></literal></term>
14581467 <listitem>
14591468 <para>
1460- maximum number of rows to process or return,
1469+ maximum number of rows to return,
14611470 or <literal>0</> for no limit
14621471 </para>
14631472 </listitem>
@@ -1575,7 +1584,7 @@ int SPI_execute_plan_with_paramlist(SPIPlanPtr <parameter>plan</parameter>,
15751584 <term><literal>long <parameter>count</parameter></literal></term>
15761585 <listitem>
15771586 <para>
1578- maximum number of rows to process or return,
1587+ maximum number of rows to return,
15791588 or <literal>0</> for no limit
15801589 </para>
15811590 </listitem>
@@ -1676,7 +1685,7 @@ int SPI_execp(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>values<
16761685 <term><literal>long <parameter>count</parameter></literal></term>
16771686 <listitem>
16781687 <para>
1679- maximum number of rows to process or return,
1688+ maximum number of rows to return,
16801689 or <literal>0</> for no limit
16811690 </para>
16821691 </listitem>
0 commit comments