Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e9135b

Browse files
committed
Doc: fix out-of-date example of SPI usage.
The "count" argument of SPI_exec() only limits execution whenthe query is actually returning rows. This was not the casebefore PG 9.0, so this example was correct when written; butwe missed updating it in commit2ddc600. Extend the exampleto show the behavior both with and without RETURNING.While here, improve the commentary and markup for the restof the example.David G. Johnston and Tom Lane, per report from Curt Kolovson.Back-patch to all supported branches.Discussion:https://postgr.es/m/CANhYJV6HWtgz_qjx_APfK0PAgLUzY-2vjLuj7i_o=TZF1LAQew@mail.gmail.com
1 parent763d262 commit2e9135b

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

‎doc/src/sgml/spi.sgml

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5305,15 +5305,16 @@ CREATE FUNCTION execq(text, integer) RETURNS int8
53055305
=> INSERT INTO a VALUES (execq('INSERT INTO a VALUES (0)', 0));
53065306
INSERT 0 1
53075307
=> SELECT execq('SELECT * FROM a', 0);
5308-
INFO: EXECQ: 0 -- inserted by execq
5309-
INFO: EXECQ: 1 -- returned by execq and inserted by upper INSERT
5308+
INFO: EXECQ: 0<lineannotation>-- inserted by execq</lineannotation>
5309+
INFO: EXECQ: 1<lineannotation>-- returned by execq and inserted by upper INSERT</lineannotation>
53105310

53115311
execq
53125312
-------
53135313
2
53145314
(1 row)
53155315

5316-
=&gt; SELECT execq('INSERT INTO a SELECT x + 2 FROM a', 1);
5316+
=&gt; SELECT execq('INSERT INTO a SELECT x + 2 FROM a RETURNING *', 1);
5317+
INFO: EXECQ: 2 <lineannotation>-- 0 + 2, then execution was stopped by count</lineannotation>
53175318
execq
53185319
-------
53195320
1
@@ -5322,21 +5323,38 @@ INFO: EXECQ: 1 -- returned by execq and inserted by upper INSERT
53225323
=&gt; SELECT execq('SELECT * FROM a', 10);
53235324
INFO: EXECQ: 0
53245325
INFO: EXECQ: 1
5325-
INFO: EXECQ: 2 -- 0 + 2, only one row inserted - as specified
5326+
INFO: EXECQ: 2
5327+
5328+
execq
5329+
-------
5330+
3 <lineannotation>-- 10 is the max value only, 3 is the real number of rows</lineannotation>
5331+
(1 row)
53265332

5333+
=&gt; SELECT execq('INSERT INTO a SELECT x + 10 FROM a', 1);
53275334
execq
53285335
-------
5329-
3 --10 is the max value only, 3 is the real number of rows
5336+
3<lineannotation>--all rows processed; count does not stop it, because nothing is returned</lineannotation>
53305337
(1 row)
53315338

5339+
=&gt; SELECT * FROM a;
5340+
x
5341+
----
5342+
0
5343+
1
5344+
2
5345+
10
5346+
11
5347+
12
5348+
(6 rows)
5349+
53325350
=&gt; DELETE FROM a;
5333-
DELETE3
5351+
DELETE6
53345352
=&gt; INSERT INTO a VALUES (execq('SELECT * FROM a', 0) + 1);
53355353
INSERT 0 1
53365354
=&gt; SELECT * FROM a;
53375355
x
53385356
---
5339-
1 -- no rows in a (0) + 1
5357+
1<lineannotation>--0 (no rows in a) + 1</lineannotation>
53405358
(1 row)
53415359

53425360
=&gt; INSERT INTO a VALUES (execq('SELECT * FROM a', 0) + 1);
@@ -5346,15 +5364,16 @@ INSERT 0 1
53465364
x
53475365
---
53485366
1
5349-
2 -- there was one row in a + 1
5367+
2<lineannotation>--1 (there was one row in a) + 1</lineannotation>
53505368
(2 rows)
53515369

5352-
-- This demonstrates the data changes visibility rule:
5370+
<lineannotation>-- This demonstrates the data changes visibility rule.</lineannotation>
5371+
<lineannotation>-- execq is called twice and sees different numbers of rows each time:</lineannotation>
53535372

53545373
=&gt; INSERT INTO a SELECT execq('SELECT * FROM a', 0) * x FROM a;
5355-
INFO: EXECQ: 1
5374+
INFO: EXECQ: 1 <lineannotation>-- results from first execq</lineannotation>
53565375
INFO: EXECQ: 2
5357-
INFO: EXECQ: 1
5376+
INFO: EXECQ: 1 <lineannotation>-- results from second execq</lineannotation>
53585377
INFO: EXECQ: 2
53595378
INFO: EXECQ: 2
53605379
INSERT 0 2
@@ -5363,10 +5382,9 @@ INSERT 0 2
53635382
---
53645383
1
53655384
2
5366-
2 -- 2 rows * 1 (x in first row)
5367-
6 -- 3 rows (2 + 1 just inserted) * 2 (x in second row)
5368-
(4 rows) ^^^^^^
5369-
rows visible to execq() in different invocations
5385+
2 <lineannotation>-- 2 rows * 1 (x in first row)</lineannotation>
5386+
6 <lineannotation>-- 3 rows (2 + 1 just inserted) * 2 (x in second row)</lineannotation>
5387+
(4 rows)
53705388
</programlisting>
53715389
</para>
53725390
</sect1>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp