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

Commitdc2d9ef

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 parentb3ca4f0 commitdc2d9ef

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
@@ -4679,15 +4679,16 @@ CREATE FUNCTION execq(text, integer) RETURNS int8
46794679
=> INSERT INTO a VALUES (execq('INSERT INTO a VALUES (0)', 0));
46804680
INSERT 0 1
46814681
=> SELECT execq('SELECT * FROM a', 0);
4682-
INFO: EXECQ: 0 -- inserted by execq
4683-
INFO: EXECQ: 1 -- returned by execq and inserted by upper INSERT
4682+
INFO: EXECQ: 0<lineannotation>-- inserted by execq</lineannotation>
4683+
INFO: EXECQ: 1<lineannotation>-- returned by execq and inserted by upper INSERT</lineannotation>
46844684

46854685
execq
46864686
-------
46874687
2
46884688
(1 row)
46894689

4690-
=&gt; SELECT execq('INSERT INTO a SELECT x + 2 FROM a', 1);
4690+
=&gt; SELECT execq('INSERT INTO a SELECT x + 2 FROM a RETURNING *', 1);
4691+
INFO: EXECQ: 2 <lineannotation>-- 0 + 2, then execution was stopped by count</lineannotation>
46914692
execq
46924693
-------
46934694
1
@@ -4696,21 +4697,38 @@ INFO: EXECQ: 1 -- returned by execq and inserted by upper INSERT
46964697
=&gt; SELECT execq('SELECT * FROM a', 10);
46974698
INFO: EXECQ: 0
46984699
INFO: EXECQ: 1
4699-
INFO: EXECQ: 2 -- 0 + 2, only one row inserted - as specified
4700+
INFO: EXECQ: 2
4701+
4702+
execq
4703+
-------
4704+
3 <lineannotation>-- 10 is the max value only, 3 is the real number of rows</lineannotation>
4705+
(1 row)
47004706

4707+
=&gt; SELECT execq('INSERT INTO a SELECT x + 10 FROM a', 1);
47014708
execq
47024709
-------
4703-
3 --10 is the max value only, 3 is the real number of rows
4710+
3<lineannotation>--all rows processed; count does not stop it, because nothing is returned</lineannotation>
47044711
(1 row)
47054712

4713+
=&gt; SELECT * FROM a;
4714+
x
4715+
----
4716+
0
4717+
1
4718+
2
4719+
10
4720+
11
4721+
12
4722+
(6 rows)
4723+
47064724
=&gt; DELETE FROM a;
4707-
DELETE3
4725+
DELETE6
47084726
=&gt; INSERT INTO a VALUES (execq('SELECT * FROM a', 0) + 1);
47094727
INSERT 0 1
47104728
=&gt; SELECT * FROM a;
47114729
x
47124730
---
4713-
1 -- no rows in a (0) + 1
4731+
1<lineannotation>--0 (no rows in a) + 1</lineannotation>
47144732
(1 row)
47154733

47164734
=&gt; INSERT INTO a VALUES (execq('SELECT * FROM a', 0) + 1);
@@ -4720,15 +4738,16 @@ INSERT 0 1
47204738
x
47214739
---
47224740
1
4723-
2 -- there was one row in a + 1
4741+
2<lineannotation>--1 (there was one row in a) + 1</lineannotation>
47244742
(2 rows)
47254743

4726-
-- This demonstrates the data changes visibility rule:
4744+
<lineannotation>-- This demonstrates the data changes visibility rule.</lineannotation>
4745+
<lineannotation>-- execq is called twice and sees different numbers of rows each time:</lineannotation>
47274746

47284747
=&gt; INSERT INTO a SELECT execq('SELECT * FROM a', 0) * x FROM a;
4729-
INFO: EXECQ: 1
4748+
INFO: EXECQ: 1 <lineannotation>-- results from first execq</lineannotation>
47304749
INFO: EXECQ: 2
4731-
INFO: EXECQ: 1
4750+
INFO: EXECQ: 1 <lineannotation>-- results from second execq</lineannotation>
47324751
INFO: EXECQ: 2
47334752
INFO: EXECQ: 2
47344753
INSERT 0 2
@@ -4737,10 +4756,9 @@ INSERT 0 2
47374756
---
47384757
1
47394758
2
4740-
2 -- 2 rows * 1 (x in first row)
4741-
6 -- 3 rows (2 + 1 just inserted) * 2 (x in second row)
4742-
(4 rows) ^^^^^^
4743-
rows visible to execq() in different invocations
4759+
2 <lineannotation>-- 2 rows * 1 (x in first row)</lineannotation>
4760+
6 <lineannotation>-- 3 rows (2 + 1 just inserted) * 2 (x in second row)</lineannotation>
4761+
(4 rows)
47444762
</programlisting>
47454763
</para>
47464764
</sect1>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp