1
1
<!--
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 $
3
3
-->
4
4
5
5
<chapter id="triggers">
@@ -10,17 +10,32 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian
10
10
</indexterm>
11
11
12
12
<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.
17
30
</para>
18
31
19
32
<sect1 id="trigger-definition">
20
33
<title>Overview of Trigger Behavior</title>
21
34
22
35
<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
24
39
<command>INSERT</command>, <command>UPDATE</command>, or
25
40
<command>DELETE</command> operation, either once per modified row,
26
41
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
45
60
</para>
46
61
47
62
<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
51
67
that fired the trigger. In contrast, a per-statement trigger is
52
68
invoked only once when an appropriate statement is executed,
53
69
regardless of the number of rows affected by that statement. In
54
70
particular, a statement that affects zero rows will still result
55
71
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 ,
58
74
respectively.
59
75
</para>
60
76
61
77
<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
65
83
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).
68
86
</para>
69
87
70
88
<para>
@@ -115,7 +133,7 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian
115
133
trigger name. In the case of before triggers, the
116
134
possibly-modified row returned by each trigger becomes the input
117
135
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
119
137
triggers are not fired.
120
138
</para>
121
139
@@ -248,11 +266,12 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian
248
266
249
267
<para>
250
268
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.
256
275
</para>
257
276
258
277
<para>
0 commit comments