@@ -316,13 +316,24 @@ int SPI_execute(const char * <parameter>command</parameter>, bool <parameter>rea
316
316
<para>
317
317
If <parameter>count</parameter> is zero then the command is executed
318
318
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,
322
327
<programlisting>
323
328
SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
324
329
</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.
326
337
</para>
327
338
328
339
<para>
@@ -331,7 +342,8 @@ SPI_execute("INSERT INTO foo SELECT * FROM bar", false, 5);
331
342
whole string will be parsed and planned before execution begins.
332
343
<function>SPI_execute</function> returns the
333
344
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
335
347
hidden commands generated by rules.
336
348
</para>
337
349
@@ -435,7 +447,8 @@ typedef struct
435
447
<term><literal>long <parameter>count</parameter></literal></term>
436
448
<listitem>
437
449
<para>
438
- maximum number of rows to process or return
450
+ maximum number of rows to return,
451
+ or <literal>0</> for no limit
439
452
</para>
440
453
</listitem>
441
454
</varlistentry>
@@ -611,15 +624,12 @@ typedef struct
611
624
<title>Notes</title>
612
625
613
626
<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
627
+ All SPI query-execution functions set both
618
628
<varname>SPI_processed</varname> and
619
629
<varname>SPI_tuptable</varname> (just the pointer, not the contents
620
630
of the structure). Save these two global variables into local
621
631
procedure variables if you need to access the result table of
622
- <function>SPI_execute</function> ora related function
632
+ <function>SPI_execute</function> oranother query-execution function
623
633
across later calls.
624
634
</para>
625
635
</refsect1>
@@ -674,7 +684,8 @@ int SPI_exec(const char * <parameter>command</parameter>, long <parameter>count<
674
684
<term><literal>long <parameter>count</parameter></literal></term>
675
685
<listitem>
676
686
<para>
677
- maximum number of rows to process or return
687
+ maximum number of rows to return,
688
+ or <literal>0</> for no limit
678
689
</para>
679
690
</listitem>
680
691
</varlistentry>
@@ -813,7 +824,8 @@ int SPI_execute_with_args(const char *<parameter>command</parameter>,
813
824
<term><literal>long <parameter>count</parameter></literal></term>
814
825
<listitem>
815
826
<para>
816
- maximum number of rows to process or return
827
+ maximum number of rows to return,
828
+ or <literal>0</> for no limit
817
829
</para>
818
830
</listitem>
819
831
</varlistentry>
@@ -1431,7 +1443,8 @@ int SPI_execute_plan(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>
1431
1443
<term><literal>long <parameter>count</parameter></literal></term>
1432
1444
<listitem>
1433
1445
<para>
1434
- maximum number of rows to process or return
1446
+ maximum number of rows to return,
1447
+ or <literal>0</> for no limit
1435
1448
</para>
1436
1449
</listitem>
1437
1450
</varlistentry>
@@ -1550,7 +1563,8 @@ int SPI_execute_plan_with_paramlist(SPIPlanPtr <parameter>plan</parameter>,
1550
1563
<term><literal>long <parameter>count</parameter></literal></term>
1551
1564
<listitem>
1552
1565
<para>
1553
- maximum number of rows to process or return
1566
+ maximum number of rows to return,
1567
+ or <literal>0</> for no limit
1554
1568
</para>
1555
1569
</listitem>
1556
1570
</varlistentry>
@@ -1650,7 +1664,8 @@ int SPI_execp(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>values<
1650
1664
<term><literal>long <parameter>count</parameter></literal></term>
1651
1665
<listitem>
1652
1666
<para>
1653
- maximum number of rows to process or return
1667
+ maximum number of rows to return,
1668
+ or <literal>0</> for no limit
1654
1669
</para>
1655
1670
</listitem>
1656
1671
</varlistentry>