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

Commitebe1be1

Browse files
committed
This patch improves the behavior of FOUND in PL/PgSQL. In Oracle,
FOUND is set whenever a SELECT INTO returns > 0 rows, *or* when anINSERT, UPDATE, or DELETE affects > 0 rows. We implemented the firstpart of this behavior, but not the second.I also improved the documentation on the various situations in whichFOUND can be set (excluding inside FOR loops, which I still need tothink about), and added some regression tests for this behavior.Neil Conway
1 parent818a33e commitebe1be1

File tree

4 files changed

+289
-130
lines changed

4 files changed

+289
-130
lines changed

‎doc/src/sgml/plpgsql.sgml‎

Lines changed: 60 additions & 12 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.1 2002/07/30 19:36:10 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/plpgsql.sgml,v 1.2 2002/08/20 05:28:23 momjian Exp $
33
-->
44

55
<chapter id="plpgsql">
@@ -126,7 +126,7 @@ END;
126126
them to define operators or use them in functional indexes.
127127
</para>
128128
<sect2 id="plpgsql-advantages">
129-
<title>Advantages of Using PL/pgSQL</title>
129+
<title>Advantages of Using<application>PL/pgSQL</application></title>
130130

131131
<itemizedlist>
132132
<listitem>
@@ -852,10 +852,58 @@ SELECT INTO <replaceable>target</replaceable> <replaceable>expressions</replacea
852852
</para>
853853

854854
<para>
855-
There is a special variable named FOUND of type
856-
<type>boolean</type> that can be used immediately after a SELECT
857-
INTO to check if an assignment had success (that is, at least one
858-
row was returned by the SELECT). For example,
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:
859907

860908
<programlisting>
861909
SELECT INTO myrec * FROM EMP WHERE empname = myname;
@@ -902,10 +950,10 @@ PERFORM <replaceable>query</replaceable>;
902950

903951
This executes a <literal>SELECT</literal>
904952
<replaceable>query</replaceable> and discards the
905-
result. <application>PL/pgSQL</application> variables are substituted
906-
in the query as usual. Also, the special variable FOUND is set to
907-
true if the query produced at least one row, or false if it produced
908-
no rows.
953+
result. <application>PL/pgSQL</application> variables are
954+
substitutedin the query as usual. Also, the special variable
955+
<literal>FOUND</literal> is set totrue if the query produced at
956+
least one row, or false if it producedno rows.
909957
</para>
910958

911959
<note>
@@ -1638,8 +1686,8 @@ FETCH <replaceable>cursor</replaceable> INTO <replaceable>target</replaceable>;
16381686
FETCH retrieves the next row from the cursor into a target,
16391687
which may be a row variable, a record variable, or a comma-separated
16401688
list of simple variables, just like SELECT INTO. As with
1641-
SELECT INTO, the special variable FOUND may be checked to see
1642-
whether a row was obtained or not.
1689+
SELECT INTO, the special variable<literal>FOUND</literal> may be
1690+
checked to seewhether a row was obtained or not.
16431691

16441692
<programlisting>
16451693
FETCH curs1 INTO rowvar;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp