11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/plpgsql.sgml,v 1.11 2002/11/15 03:22:30 momjian Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/plpgsql.sgml,v 1.12 2002/11/23 03:59:05 momjian Exp $
33-->
44
55<chapter id="plpgsql">
@@ -674,24 +674,25 @@ RENAME this_var TO that_var;
674674 <title>Expressions</title>
675675
676676 <para>
677- All expressions used in <application>PL/pgSQL</application> statements
678- are processed using the server's regular SQL executor. Expressions that
679- appear to contain
680- constants may in fact require run-time evaluation
681- (e.g. <literal>'now'</literal> for the
682- < type>timestamp</type> type ) so
683- it is impossible for the <application>PL/pgSQL</application> parser
684- to identify real constant values other than the NULL keyword. All
685- expressions are evaluated internally by executing a query
677+ All expressions used in <application>PL/pgSQL</application>
678+ statements are processed using the server's regular
679+ <acronym>SQL</acronym> executor. Expressions that appear to
680+ contain constants may in fact require run-time evaluation
681+ (e.g. <literal>'now'</literal> for the <type>timestamp</type>
682+ type) so it is impossible for the
683+ <application>PL/pgSQL</application> parser to identify real
684+ constant values other than the NULL keyword. All expressions are
685+ evaluated internally by executing a query
686686<synopsis>
687687SELECT <replaceable>expression</replaceable>
688688</synopsis>
689- using the <acronym>SPI</acronym> manager. In the expression, occurrences
690- of <application>PL/pgSQL</application> variable
689+ using the <acronym>SPI</acronym> manager. In the expression,
690+ occurrences of <application>PL/pgSQL</application> variable
691691 identifiers are replaced by parameters and the actual values from
692692 the variables are passed to the executor in the parameter array.
693- This allows the query plan for the SELECT to be prepared just once
694- and then re-used for subsequent evaluations.
693+ This allows the query plan for the <command>SELECT</command> to
694+ be prepared just once and then re-used for subsequent
695+ evaluations.
695696 </para>
696697
697698 <para>
@@ -1100,41 +1101,43 @@ GET DIAGNOSTICS <replaceable>variable</replaceable> = <replaceable>item</replace
11001101 <itemizedlist>
11011102 <listitem>
11021103 <para>
1103- A SELECT INTO statement sets <literal>FOUND</literal>
1104- true if it returns a row, false if no row is returned.
1104+ A <command>SELECT INTO</command> statement sets
1105+ <literal>FOUND</literal> true if it returns a row, false if no
1106+ row is returned.
11051107 </para>
11061108 </listitem>
11071109 <listitem>
11081110 <para>
1109- A PERFORM statement sets <literal>FOUND</literal>
1111+ A <command> PERFORM</> statement sets <literal>FOUND</literal>
11101112 true if it produces (discards) a row, false if no row is
11111113 produced.
11121114 </para>
11131115 </listitem>
11141116 <listitem>
11151117 <para>
1116- UPDATE, INSERT, and DELETE statements set
1117- <literal>FOUND</literal> true if at least one row is
1118- affected, false if no row is affected.
1118+ <command> UPDATE</>, <command> INSERT</> , and <command> DELETE</>
1119+ statements set <literal>FOUND</literal> true if at least one
1120+ row is affected, false if no row is affected.
11191121 </para>
11201122 </listitem>
11211123 <listitem>
11221124 <para>
1123- A FETCH statement sets <literal>FOUND</literal>
1125+ A <command> FETCH</> statement sets <literal>FOUND</literal>
11241126 true if it returns a row, false if no row is returned.
11251127 </para>
11261128 </listitem>
11271129 <listitem>
11281130 <para>
1129- A FOR statement sets <literal>FOUND</literal>
1130- true if it iterates one or more times, else false.
1131- This applies to all three variants of the FOR statement
1132- (integer FOR loops, record-set FOR loops, and dynamic
1133- record-set FOR loops). <literal>FOUND</literal> is only set
1134- when the FOR loop exits: inside the execution of the loop,
1135- <literal>FOUND</literal> is not modified by the FOR statement,
1136- although it may be changed by the execution of other
1137- statements within the loop body.
1131+ A <command>FOR</> statement sets <literal>FOUND</literal> true
1132+ if it iterates one or more times, else false. This applies to
1133+ all three variants of the <command>FOR</> statement (integer
1134+ <command>FOR</> loops, record-set <command>FOR</> loops, and
1135+ dynamic record-set <command>FOR</>
1136+ loops). <literal>FOUND</literal> is only set when the
1137+ <command>FOR</> loop exits: inside the execution of the loop,
1138+ <literal>FOUND</literal> is not modified by the
1139+ <command>FOR</> statement, although it may be changed by the
1140+ execution of other statements within the loop body.
11381141 </para>
11391142 </listitem>
11401143 </itemizedlist>
@@ -1975,7 +1978,7 @@ RAISE EXCEPTION ''Inexistent ID --> %'',user_id;
19751978 <application>PL/pgSQL</application> can be used to define trigger
19761979 procedures. A trigger procedure is created with the
19771980 <command>CREATE FUNCTION</> command as a function with no
1978- arguments and a return type of <type>TRIGGER </type>. Note that
1981+ arguments and a return type of <type>trigger </type>. Note that
19791982 the function must be declared with no arguments even if it expects
19801983 to receive arguments specified in <command>CREATE TRIGGER</> ---
19811984 trigger arguments are passed via <varname>TG_ARGV</>, as described
@@ -1992,8 +1995,9 @@ RAISE EXCEPTION ''Inexistent ID --> %'',user_id;
19921995 <term><varname>NEW</varname></term>
19931996 <listitem>
19941997 <para>
1995- Data type <type>RECORD</type>; variable holding the new database row for INSERT/UPDATE
1996- operations in ROW level triggers.
1998+ Data type <type>RECORD</type>; variable holding the new
1999+ database row for INSERT/UPDATE operations in ROW level
2000+ triggers. This variable is NULL in STATEMENT level triggers.
19972001 </para>
19982002 </listitem>
19992003 </varlistentry>
@@ -2002,8 +2006,9 @@ RAISE EXCEPTION ''Inexistent ID --> %'',user_id;
20022006 <term><varname>OLD</varname></term>
20032007 <listitem>
20042008 <para>
2005- Data type <type>RECORD</type>; variable holding the old database row for UPDATE/DELETE
2006- operations in ROW level triggers.
2009+ Data type <type>RECORD</type>; variable holding the old
2010+ database row for UPDATE/DELETE operations in ROW level
2011+ triggers. This variable is NULL in STATEMENT level triggers.
20072012 </para>
20082013 </listitem>
20092014 </varlistentry>
@@ -2098,22 +2103,23 @@ RAISE EXCEPTION ''Inexistent ID --> %'',user_id;
20982103
20992104 <para>
21002105 A trigger function must return either NULL or a record/row value
2101- having exactly the structure of the table the trigger was fired for.
2102- Triggers fired BEFORE may return NULL to signal the trigger manager
2103- to skip the rest of the operation for this row (ie, subsequent triggers
2104- are not fired, and the INSERT/UPDATE/DELETE does not occur for this
2105- row). If a non-NULL value is returned then the operation proceeds with
2106- that row value. Note that returning a row value different from the
2107- original value of NEW alters the row that will be inserted or updated.
2108- It is possible to replace single values directly
2109- in NEW and return that, or to build a complete new record/row to
2110- return.
2106+ having exactly the structure of the table the trigger was fired
2107+ for. The return value of a BEFORE or AFTER STATEMENT level
2108+ trigger, or an AFTER ROW level trigger is ignored; it may as well
2109+ return NULL. However, any of these types of triggers can still
2110+ abort the entire trigger operation by raising an error.
21112111 </para>
21122112
21132113 <para>
2114- The return value of a trigger fired AFTER is ignored; it may as well
2115- always return a NULL value. But an AFTER trigger can still abort the
2116- operation by raising an error.
2114+ ROW level triggers fired BEFORE may return NULL to signal the
2115+ trigger manager to skip the rest of the operation for this row
2116+ (ie, subsequent triggers are not fired, and the
2117+ INSERT/UPDATE/DELETE does not occur for this row). If a non-NULL
2118+ value is returned then the operation proceeds with that row value.
2119+ Note that returning a row value different from the original value
2120+ of NEW alters the row that will be inserted or updated. It is
2121+ possible to replace single values directly in NEW and return that,
2122+ or to build a complete new record/row to return.
21172123 </para>
21182124
21192125 <example>
@@ -2143,7 +2149,7 @@ CREATE FUNCTION emp_stamp () RETURNS TRIGGER AS '
21432149 RAISE EXCEPTION ''% cannot have NULL salary'', NEW.empname;
21442150 END IF;
21452151
2146- -- Who works for us when she must pay for?
2152+ -- Who works for us when she must pay for it ?
21472153 IF NEW.salary < 0 THEN
21482154 RAISE EXCEPTION ''% cannot have a negative salary'', NEW.empname;
21492155 END IF;
0 commit comments