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

Commit04911fa

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 parent410a0d6 commit04911fa

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
@@ -4670,15 +4670,16 @@ CREATE FUNCTION execq(text, integer) RETURNS int8
46704670
=> INSERT INTO a VALUES (execq('INSERT INTO a VALUES (0)', 0));
46714671
INSERT 0 1
46724672
=> SELECT execq('SELECT * FROM a', 0);
4673-
INFO: EXECQ: 0 -- inserted by execq
4674-
INFO: EXECQ: 1 -- returned by execq and inserted by upper INSERT
4673+
INFO: EXECQ: 0<lineannotation>-- inserted by execq</lineannotation>
4674+
INFO: EXECQ: 1<lineannotation>-- returned by execq and inserted by upper INSERT</lineannotation>
46754675

46764676
execq
46774677
-------
46784678
2
46794679
(1 row)
46804680

4681-
=&gt; SELECT execq('INSERT INTO a SELECT x + 2 FROM a', 1);
4681+
=&gt; SELECT execq('INSERT INTO a SELECT x + 2 FROM a RETURNING *', 1);
4682+
INFO: EXECQ: 2 <lineannotation>-- 0 + 2, then execution was stopped by count</lineannotation>
46824683
execq
46834684
-------
46844685
1
@@ -4687,21 +4688,38 @@ INFO: EXECQ: 1 -- returned by execq and inserted by upper INSERT
46874688
=&gt; SELECT execq('SELECT * FROM a', 10);
46884689
INFO: EXECQ: 0
46894690
INFO: EXECQ: 1
4690-
INFO: EXECQ: 2 -- 0 + 2, only one row inserted - as specified
4691+
INFO: EXECQ: 2
4692+
4693+
execq
4694+
-------
4695+
3 <lineannotation>-- 10 is the max value only, 3 is the real number of rows</lineannotation>
4696+
(1 row)
46914697

4698+
=&gt; SELECT execq('INSERT INTO a SELECT x + 10 FROM a', 1);
46924699
execq
46934700
-------
4694-
3 --10 is the max value only, 3 is the real number of rows
4701+
3<lineannotation>--all rows processed; count does not stop it, because nothing is returned</lineannotation>
46954702
(1 row)
46964703

4704+
=&gt; SELECT * FROM a;
4705+
x
4706+
----
4707+
0
4708+
1
4709+
2
4710+
10
4711+
11
4712+
12
4713+
(6 rows)
4714+
46974715
=&gt; DELETE FROM a;
4698-
DELETE3
4716+
DELETE6
46994717
=&gt; INSERT INTO a VALUES (execq('SELECT * FROM a', 0) + 1);
47004718
INSERT 0 1
47014719
=&gt; SELECT * FROM a;
47024720
x
47034721
---
4704-
1 -- no rows in a (0) + 1
4722+
1<lineannotation>--0 (no rows in a) + 1</lineannotation>
47054723
(1 row)
47064724

47074725
=&gt; INSERT INTO a VALUES (execq('SELECT * FROM a', 0) + 1);
@@ -4711,15 +4729,16 @@ INSERT 0 1
47114729
x
47124730
---
47134731
1
4714-
2 -- there was one row in a + 1
4732+
2<lineannotation>--1 (there was one row in a) + 1</lineannotation>
47154733
(2 rows)
47164734

4717-
-- This demonstrates the data changes visibility rule:
4735+
<lineannotation>-- This demonstrates the data changes visibility rule.</lineannotation>
4736+
<lineannotation>-- execq is called twice and sees different numbers of rows each time:</lineannotation>
47184737

47194738
=&gt; INSERT INTO a SELECT execq('SELECT * FROM a', 0) * x FROM a;
4720-
INFO: EXECQ: 1
4739+
INFO: EXECQ: 1 <lineannotation>-- results from first execq</lineannotation>
47214740
INFO: EXECQ: 2
4722-
INFO: EXECQ: 1
4741+
INFO: EXECQ: 1 <lineannotation>-- results from second execq</lineannotation>
47234742
INFO: EXECQ: 2
47244743
INFO: EXECQ: 2
47254744
INSERT 0 2
@@ -4728,10 +4747,9 @@ INSERT 0 2
47284747
---
47294748
1
47304749
2
4731-
2 -- 2 rows * 1 (x in first row)
4732-
6 -- 3 rows (2 + 1 just inserted) * 2 (x in second row)
4733-
(4 rows) ^^^^^^
4734-
rows visible to execq() in different invocations
4750+
2 <lineannotation>-- 2 rows * 1 (x in first row)</lineannotation>
4751+
6 <lineannotation>-- 3 rows (2 + 1 just inserted) * 2 (x in second row)</lineannotation>
4752+
(4 rows)
47354753
</programlisting>
47364754
</para>
47374755
</sect1>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp