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

Commit99fd5cb

Browse files
committed
FOUND patch was a bit over-enthusiastic: SQL commands that are not
INSERT, UPDATE, or DELETE shouldn't change FOUND. IMHO anyway.Also, try to make documentation a little clearer.
1 parent5241a62 commit99fd5cb

File tree

2 files changed

+62
-64
lines changed

2 files changed

+62
-64
lines changed

‎doc/src/sgml/plpgsql.sgml

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/plpgsql.sgml,v 1.3 2002/08/22 00:01:40 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/plpgsql.sgml,v 1.4 2002/08/29 04:12:02 tgl Exp $
33
-->
44

55
<chapter id="plpgsql">
@@ -852,58 +852,10 @@ SELECT INTO <replaceable>target</replaceable> <replaceable>expressions</replacea
852852
</para>
853853

854854
<para>
855-
There is a special variable named <literal>FOUND</literal> of
856-
type <type>boolean</type>. The initial value of
857-
<literal>FOUND</literal> is false; it is set to true when one of
858-
the following events occurs:
859-
<itemizedlist>
860-
<listitem>
861-
<para>
862-
A SELECT INTO statement is executed, and it returns one or
863-
more rows.
864-
</para>
865-
</listitem>
866-
<listitem>
867-
<para>
868-
A UPDATE, INSERT, or DELETE statement is executed, and it
869-
affects one or more rows.
870-
</para>
871-
</listitem>
872-
<listitem>
873-
<para>
874-
A PERFORM statement is executed, and it discards one or more
875-
rows.
876-
</para>
877-
</listitem>
878-
<listitem>
879-
<para>
880-
A FETCH statement is executed, and it returns an additional
881-
row.
882-
</para>
883-
</listitem>
884-
<listitem>
885-
<para>
886-
A FOR statement is executed, and it iterates one or more
887-
times. This applies to all three variants of the FOR statement
888-
(integer FOR loops, record-set FOR loops, and dynamic
889-
record-set FOR loops). <literal>FOUND</literal> is only set
890-
when the FOR loop exits: inside the execution of the loop,
891-
<literal>FOUND</literal> is not modified, although it may be
892-
set by the execution of other statements.
893-
</para>
894-
</listitem>
895-
</itemizedlist>
896-
If none of these events occur, <literal>FOUND</literal> is set to
897-
false. <literal>FOUND</literal> is a local variable; any changes
898-
to it effect only the current <application>PL/pgSQL</application>
899-
function.
900-
</para>
901-
902-
<para>
903-
You can use <literal>FOUND</literal> immediately after a SELECT
904-
INTO statement to determine whether the assignment was successful
905-
(that is, at least one row was was returned by the SELECT
906-
statement). For example:
855+
You can use <literal>FOUND</literal> immediately after a SELECT
856+
INTO statement to determine whether the assignment was successful
857+
(that is, at least one row was was returned by the SELECT
858+
statement). For example:
907859

908860
<programlisting>
909861
SELECT INTO myrec * FROM EMP WHERE empname = myname;
@@ -1116,6 +1068,58 @@ GET DIAGNOSTICS <replaceable>variable</replaceable> = <replaceable>item</replace
11161068
</programlisting>
11171069
</informalexample>
11181070
</para>
1071+
1072+
<para>
1073+
There is a special variable named <literal>FOUND</literal> of
1074+
type <type>boolean</type>. <literal>FOUND</literal> starts out
1075+
false within each <application>PL/pgSQL</application> function.
1076+
It is set by each of the following types of statements:
1077+
<itemizedlist>
1078+
<listitem>
1079+
<para>
1080+
A SELECT INTO statement sets <literal>FOUND</literal>
1081+
true if it returns a row, false if no row is returned.
1082+
</para>
1083+
</listitem>
1084+
<listitem>
1085+
<para>
1086+
A PERFORM statement sets <literal>FOUND</literal>
1087+
true if it produces (discards) a row, false if no row is
1088+
produced.
1089+
</para>
1090+
</listitem>
1091+
<listitem>
1092+
<para>
1093+
UPDATE, INSERT, and DELETE statements set
1094+
<literal>FOUND</literal> true if at least one row is
1095+
affected, false if no row is affected.
1096+
</para>
1097+
</listitem>
1098+
<listitem>
1099+
<para>
1100+
A FETCH statement sets <literal>FOUND</literal>
1101+
true if it returns a row, false if no row is returned.
1102+
</para>
1103+
</listitem>
1104+
<listitem>
1105+
<para>
1106+
A FOR statement sets <literal>FOUND</literal>
1107+
true if it iterates one or more times, else false.
1108+
This applies to all three variants of the FOR statement
1109+
(integer FOR loops, record-set FOR loops, and dynamic
1110+
record-set FOR loops). <literal>FOUND</literal> is only set
1111+
when the FOR loop exits: inside the execution of the loop,
1112+
<literal>FOUND</literal> is not modified by the FOR statement,
1113+
although it may be changed by the execution of other
1114+
statements within the loop body.
1115+
</para>
1116+
</listitem>
1117+
</itemizedlist>
1118+
<literal>FOUND</literal> is a local variable; any changes
1119+
to it affect only the current <application>PL/pgSQL</application>
1120+
function.
1121+
</para>
1122+
11191123
</sect2>
11201124
</sect1>
11211125

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* procedural language
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.58 2002/08/24 15:00:47 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.59 2002/08/29 04:12:03 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -1844,11 +1844,6 @@ exec_stmt_execsql(PLpgSQL_execstate * estate,
18441844
PLpgSQL_expr*expr=stmt->sqlstmt;
18451845
boolisnull;
18461846

1847-
/*
1848-
* Set magic FOUND variable to false
1849-
*/
1850-
exec_set_found(estate, false);
1851-
18521847
/*
18531848
* On the first call for this expression generate the plan
18541849
*/
@@ -1927,16 +1922,15 @@ exec_stmt_execsql(PLpgSQL_execstate * estate,
19271922
caseSPI_OK_SELINTO:
19281923
break;
19291924

1925+
caseSPI_OK_INSERT:
1926+
caseSPI_OK_DELETE:
1927+
caseSPI_OK_UPDATE:
19301928
/*
19311929
* If the INSERT, DELETE, or UPDATE query affected at least
19321930
* one tuple, set the magic 'FOUND' variable to true. This
19331931
* conforms with the behavior of PL/SQL.
19341932
*/
1935-
caseSPI_OK_INSERT:
1936-
caseSPI_OK_DELETE:
1937-
caseSPI_OK_UPDATE:
1938-
if (SPI_processed>0)
1939-
exec_set_found(estate, true);
1933+
exec_set_found(estate, (SPI_processed!=0));
19401934
break;
19411935

19421936
caseSPI_OK_SELECT:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp