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

Commit137b131

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 parent4e465aa commit137b131

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
@@ -5314,15 +5314,16 @@ CREATE FUNCTION execq(text, integer) RETURNS int8
53145314
=> INSERT INTO a VALUES (execq('INSERT INTO a VALUES (0)', 0));
53155315
INSERT 0 1
53165316
=> SELECT execq('SELECT * FROM a', 0);
5317-
INFO: EXECQ: 0 -- inserted by execq
5318-
INFO: EXECQ: 1 -- returned by execq and inserted by upper INSERT
5317+
INFO: EXECQ: 0<lineannotation>-- inserted by execq</lineannotation>
5318+
INFO: EXECQ: 1<lineannotation>-- returned by execq and inserted by upper INSERT</lineannotation>
53195319

53205320
execq
53215321
-------
53225322
2
53235323
(1 row)
53245324

5325-
=&gt; SELECT execq('INSERT INTO a SELECT x + 2 FROM a', 1);
5325+
=&gt; SELECT execq('INSERT INTO a SELECT x + 2 FROM a RETURNING *', 1);
5326+
INFO: EXECQ: 2 <lineannotation>-- 0 + 2, then execution was stopped by count</lineannotation>
53265327
execq
53275328
-------
53285329
1
@@ -5331,21 +5332,38 @@ INFO: EXECQ: 1 -- returned by execq and inserted by upper INSERT
53315332
=&gt; SELECT execq('SELECT * FROM a', 10);
53325333
INFO: EXECQ: 0
53335334
INFO: EXECQ: 1
5334-
INFO: EXECQ: 2 -- 0 + 2, only one row inserted - as specified
5335+
INFO: EXECQ: 2
5336+
5337+
execq
5338+
-------
5339+
3 <lineannotation>-- 10 is the max value only, 3 is the real number of rows</lineannotation>
5340+
(1 row)
53355341

5342+
=&gt; SELECT execq('INSERT INTO a SELECT x + 10 FROM a', 1);
53365343
execq
53375344
-------
5338-
3 --10 is the max value only, 3 is the real number of rows
5345+
3<lineannotation>--all rows processed; count does not stop it, because nothing is returned</lineannotation>
53395346
(1 row)
53405347

5348+
=&gt; SELECT * FROM a;
5349+
x
5350+
----
5351+
0
5352+
1
5353+
2
5354+
10
5355+
11
5356+
12
5357+
(6 rows)
5358+
53415359
=&gt; DELETE FROM a;
5342-
DELETE3
5360+
DELETE6
53435361
=&gt; INSERT INTO a VALUES (execq('SELECT * FROM a', 0) + 1);
53445362
INSERT 0 1
53455363
=&gt; SELECT * FROM a;
53465364
x
53475365
---
5348-
1 -- no rows in a (0) + 1
5366+
1<lineannotation>--0 (no rows in a) + 1</lineannotation>
53495367
(1 row)
53505368

53515369
=&gt; INSERT INTO a VALUES (execq('SELECT * FROM a', 0) + 1);
@@ -5355,15 +5373,16 @@ INSERT 0 1
53555373
x
53565374
---
53575375
1
5358-
2 -- there was one row in a + 1
5376+
2<lineannotation>--1 (there was one row in a) + 1</lineannotation>
53595377
(2 rows)
53605378

5361-
-- This demonstrates the data changes visibility rule:
5379+
<lineannotation>-- This demonstrates the data changes visibility rule.</lineannotation>
5380+
<lineannotation>-- execq is called twice and sees different numbers of rows each time:</lineannotation>
53625381

53635382
=&gt; INSERT INTO a SELECT execq('SELECT * FROM a', 0) * x FROM a;
5364-
INFO: EXECQ: 1
5383+
INFO: EXECQ: 1 <lineannotation>-- results from first execq</lineannotation>
53655384
INFO: EXECQ: 2
5366-
INFO: EXECQ: 1
5385+
INFO: EXECQ: 1 <lineannotation>-- results from second execq</lineannotation>
53675386
INFO: EXECQ: 2
53685387
INFO: EXECQ: 2
53695388
INSERT 0 2
@@ -5372,10 +5391,9 @@ INSERT 0 2
53725391
---
53735392
1
53745393
2
5375-
2 -- 2 rows * 1 (x in first row)
5376-
6 -- 3 rows (2 + 1 just inserted) * 2 (x in second row)
5377-
(4 rows) ^^^^^^
5378-
rows visible to execq() in different invocations
5394+
2 <lineannotation>-- 2 rows * 1 (x in first row)</lineannotation>
5395+
6 <lineannotation>-- 3 rows (2 + 1 just inserted) * 2 (x in second row)</lineannotation>
5396+
(4 rows)
53795397
</programlisting>
53805398
</para>
53815399
</sect1>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp