Bug in documentation: https://www.postgresql.org/docs/current/spi-examples.html
Curt Kolovson <ckolovson@gmail.com>
From: Curt Kolovson <ckolovson@gmail.com>
To: pgsql-docs@lists.postgresql.org
Date: 2023-07-17T23:52:53Z
Lists: pgsql-docs
The actual results (shown below) are different than shown on this doc
page. The reason is because the second parameter to the UDF that is
passed to SPI_exec is the maximum number of rows to return, or 0 for
no limit. It is not the maximum number of rows to process. In the case
of "SELECT execq('INSERT INTO a SELECT x + 2 FROM a', 1)", it returned
0 rows, but it inserted (processed) 2 rows. This example should be
corrected.
Curt
db=# SELECT execq('CREATE TABLE a (x integer)', 0);
execq
-------
0
(1 row)
db=# INSERT INTO a VALUES (execq('INSERT INTO a VALUES (0)', 0));
INSERT 0 1
db=# SELECT execq('SELECT * FROM a', 0);
INFO: EXECQ: 0
INFO: EXECQ: 1
execq
-------
2
(1 row)
db=# SELECT execq('INSERT INTO a SELECT x + 2 FROM a', 1);
execq
-------
2
(1 row)
db=# SELECT execq('SELECT * FROM a', 10);
INFO: EXECQ: 0
INFO: EXECQ: 1
INFO: EXECQ: 2
INFO: EXECQ: 3
execq
-------
4
(1 row)
Commits
-
Doc: fix out-of-date example of SPI usage.
- f9278cb0ae94 15.4 landed
- e6e451c1d7e5 16.0 landed
- df73e8bad6e4 11.21 landed
- dc2d9efcb47e 13.12 landed
- 2e9135b94093 14.9 landed
- 137b131d6fbd 17.0 landed
- 04911fa767fd 12.16 landed
-
Fix SPI documentation for new handling of ExecutorRun's count parameter.
- 2ddc600f8f02 9.3.0 cited