@@ -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
@@ -432,7 +444,8 @@ typedef struct
432
444
<term><literal>long <parameter>count</parameter></literal></term>
433
445
<listitem>
434
446
<para>
435
- maximum number of rows to process or return
447
+ maximum number of rows to return,
448
+ or <literal>0</> for no limit
436
449
</para>
437
450
</listitem>
438
451
</varlistentry>
@@ -608,15 +621,12 @@ typedef struct
608
621
<title>Notes</title>
609
622
610
623
<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
615
625
<varname>SPI_processed</varname> and
616
626
<varname>SPI_tuptable</varname> (just the pointer, not the contents
617
627
of the structure). Save these two global variables into local
618
628
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
620
630
across later calls.
621
631
</para>
622
632
</refsect1>
@@ -671,7 +681,8 @@ int SPI_exec(const char * <parameter>command</parameter>, long <parameter>count<
671
681
<term><literal>long <parameter>count</parameter></literal></term>
672
682
<listitem>
673
683
<para>
674
- maximum number of rows to process or return
684
+ maximum number of rows to return,
685
+ or <literal>0</> for no limit
675
686
</para>
676
687
</listitem>
677
688
</varlistentry>
@@ -808,7 +819,8 @@ int SPI_execute_with_args(const char *<parameter>command</parameter>,
808
819
<term><literal>long <parameter>count</parameter></literal></term>
809
820
<listitem>
810
821
<para>
811
- maximum number of rows to process or return
822
+ maximum number of rows to return,
823
+ or <literal>0</> for no limit
812
824
</para>
813
825
</listitem>
814
826
</varlistentry>
@@ -1424,7 +1436,8 @@ int SPI_execute_plan(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>
1424
1436
<term><literal>long <parameter>count</parameter></literal></term>
1425
1437
<listitem>
1426
1438
<para>
1427
- maximum number of rows to process or return
1439
+ maximum number of rows to return,
1440
+ or <literal>0</> for no limit
1428
1441
</para>
1429
1442
</listitem>
1430
1443
</varlistentry>
@@ -1541,7 +1554,8 @@ int SPI_execute_plan_with_paramlist(SPIPlanPtr <parameter>plan</parameter>,
1541
1554
<term><literal>long <parameter>count</parameter></literal></term>
1542
1555
<listitem>
1543
1556
<para>
1544
- maximum number of rows to process or return
1557
+ maximum number of rows to return,
1558
+ or <literal>0</> for no limit
1545
1559
</para>
1546
1560
</listitem>
1547
1561
</varlistentry>
@@ -1641,7 +1655,8 @@ int SPI_execp(SPIPlanPtr <parameter>plan</parameter>, Datum * <parameter>values<
1641
1655
<term><literal>long <parameter>count</parameter></literal></term>
1642
1656
<listitem>
1643
1657
<para>
1644
- maximum number of rows to process or return
1658
+ maximum number of rows to return,
1659
+ or <literal>0</> for no limit
1645
1660
</para>
1646
1661
</listitem>
1647
1662
</varlistentry>