11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.44 2005/10/13 21:09:38 tgl Exp $
33-->
44
55 <chapter id="triggers">
@@ -10,17 +10,32 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian
1010 </indexterm>
1111
1212 <para>
13- This chapter describes how to write trigger functions. Trigger
14- functions can be written in C or in some of the available procedural
15- languages. It is not currently possible to write a SQL-language
16- trigger function.
13+ This chapter provides general information about writing trigger functions.
14+ Trigger functions can be written in most of the available procedural
15+ languages, including
16+ <application>PL/pgSQL</application> (<xref linkend="plpgsql">),
17+ <application>PL/Tcl</application> (<xref linkend="pltcl">),
18+ <application>PL/Perl</application> (<xref linkend="plperl">), and
19+ <application>PL/Python</application> (<xref linkend="plpython">).
20+ After reading this chapter, you should consult the chapter for
21+ your favorite procedural language to find out the language-specific
22+ details of writing a trigger in it.
23+ </para>
24+
25+ <para>
26+ It is also possible to write a trigger function in C, although
27+ most people find it easier to use one of the procedural languages.
28+ It is not currently possible to write a trigger function in the
29+ plain SQL function language.
1730 </para>
1831
1932 <sect1 id="trigger-definition">
2033 <title>Overview of Trigger Behavior</title>
2134
2235 <para>
23- A trigger can be defined to execute before or after an
36+ A trigger is a specification that the database should automatically
37+ execute a particular function whenever a certain type of operation is
38+ performed. Triggers can be defined to execute either before or after any
2439 <command>INSERT</command>, <command>UPDATE</command>, or
2540 <command>DELETE</command> operation, either once per modified row,
2641 or once per <acronym>SQL</acronym> statement.
@@ -45,26 +60,29 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian
4560 </para>
4661
4762 <para>
48- There are two types of triggers: per-row triggers and
49- per-statement triggers. In a per-row trigger, the trigger function
50- is invoked once for every row that is affected by the statement
63+ <productname>PostgreSQL</productname> offers both <firstterm>per-row</>
64+ triggers and <firstterm>per-statement</> triggers. With a per-row
65+ trigger, the trigger function
66+ is invoked once for each row that is affected by the statement
5167 that fired the trigger. In contrast, a per-statement trigger is
5268 invoked only once when an appropriate statement is executed,
5369 regardless of the number of rows affected by that statement. In
5470 particular, a statement that affects zero rows will still result
5571 in the execution of any applicable per-statement triggers. These
56- two types of triggers are sometimes called <quote >row-level
57- triggers</quote> and <quote >statement-level triggers</quote> ,
72+ two types of triggers are sometimes called <firstterm >row-level</>
73+ triggers and <firstterm >statement-level</> triggers ,
5874 respectively.
5975 </para>
6076
6177 <para>
62- Statement-level <quote>before</> triggers naturally fire before the
63- statement starts to do anything, while statement-level <quote>after</>
64- triggers fire at the very end of the statement. Row-level <quote>before</>
78+ Triggers are also classified as <firstterm>before</> triggers and
79+ <firstterm>after</> triggers.
80+ Statement-level before triggers naturally fire before the
81+ statement starts to do anything, while statement-level after
82+ triggers fire at the very end of the statement. Row-level before
6583 triggers fire immediately before a particular row is operated on,
66- while row-level <quote> after</> triggers fire at the end of the statement
67- (but before any statement-level <quote> after</> triggers).
84+ while row-level after triggers fire at the end of the statement
85+ (but before any statement-level after triggers).
6886 </para>
6987
7088 <para>
@@ -115,7 +133,7 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian
115133 trigger name. In the case of before triggers, the
116134 possibly-modified row returned by each trigger becomes the input
117135 to the next trigger. If any before trigger returns
118- <symbol>NULL</>, the operation is abandoned and subsequent
136+ <symbol>NULL</>, the operation is abandoned for that row and subsequent
119137 triggers are not fired.
120138 </para>
121139
@@ -248,11 +266,12 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian
248266
249267 <para>
250268 This section describes the low-level details of the interface to a
251- trigger function. This information is only needed when writing a
252- trigger function in C. If you are using a higher-level
253- language then these details are handled for you. The documentation
254- of each procedural language explains how to write a trigger in that
255- language.
269+ trigger function. This information is only needed when writing
270+ trigger functions in C. If you are using a higher-level language then
271+ these details are handled for you. In most cases you should consider
272+ using a procedural language before writing your triggers in C. The
273+ documentation of each procedural language explains how to write a
274+ trigger in that language.
256275 </para>
257276
258277 <para>
0 commit comments