From: Tom Lane Date: Thu, 13 Oct 2005 21:09:38 +0000 (+0000) Subject: Adjust the discussion of triggers to more clearly guide people in the X-Git-Tag: REL8_1_0BETA4~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6f9cb4eb4366c774b6d8154b3853febc3b43fbe6;p=postgresql Adjust the discussion of triggers to more clearly guide people in the direction of writing triggers in a procedural language, rather than C. Per discussion. --- diff --git a/doc/src/sgml/trigger.sgml b/doc/src/sgml/trigger.sgml index 966e556a71..4d4ddd4361 100644 --- a/doc/src/sgml/trigger.sgml +++ b/doc/src/sgml/trigger.sgml @@ -1,5 +1,5 @@ @@ -10,17 +10,32 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian - This chapter describes how to write trigger functions. Trigger - functions can be written in C or in some of the available procedural - languages. It is not currently possible to write a SQL-language - trigger function. + This chapter provides general information about writing trigger functions. + Trigger functions can be written in most of the available procedural + languages, including + PL/pgSQL (), + PL/Tcl (), + PL/Perl (), and + PL/Python (). + After reading this chapter, you should consult the chapter for + your favorite procedural language to find out the language-specific + details of writing a trigger in it. + + + + It is also possible to write a trigger function in C, although + most people find it easier to use one of the procedural languages. + It is not currently possible to write a trigger function in the + plain SQL function language. Overview of Trigger Behavior - A trigger can be defined to execute before or after an + A trigger is a specification that the database should automatically + execute a particular function whenever a certain type of operation is + performed. Triggers can be defined to execute either before or after any INSERT, UPDATE, or DELETE operation, either once per modified row, or once per SQL statement. @@ -45,26 +60,29 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian - There are two types of triggers: per-row triggers and - per-statement triggers. In a per-row trigger, the trigger function - is invoked once for every row that is affected by the statement + PostgreSQL offers both per-row + triggers and per-statement triggers. With a per-row + trigger, the trigger function + is invoked once for each row that is affected by the statement that fired the trigger. In contrast, a per-statement trigger is invoked only once when an appropriate statement is executed, regardless of the number of rows affected by that statement. In particular, a statement that affects zero rows will still result in the execution of any applicable per-statement triggers. These - two types of triggers are sometimes called row-level - triggers and statement-level triggers, + two types of triggers are sometimes called row-level + triggers and statement-level triggers, respectively. - Statement-level before triggers naturally fire before the - statement starts to do anything, while statement-level after - triggers fire at the very end of the statement. Row-level before + Triggers are also classified as before triggers and + after triggers. + Statement-level before triggers naturally fire before the + statement starts to do anything, while statement-level after + triggers fire at the very end of the statement. Row-level before triggers fire immediately before a particular row is operated on, - while row-level after triggers fire at the end of the statement - (but before any statement-level after triggers). + while row-level after triggers fire at the end of the statement + (but before any statement-level after triggers). @@ -115,7 +133,7 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian trigger name. In the case of before triggers, the possibly-modified row returned by each trigger becomes the input to the next trigger. If any before trigger returns - NULL, the operation is abandoned and subsequent + NULL, the operation is abandoned for that row and subsequent triggers are not fired. @@ -248,11 +266,12 @@ $PostgreSQL: pgsql/doc/src/sgml/trigger.sgml,v 1.43 2005/10/13 02:23:12 momjian This section describes the low-level details of the interface to a - trigger function. This information is only needed when writing a - trigger function in C. If you are using a higher-level - language then these details are handled for you. The documentation - of each procedural language explains how to write a trigger in that - language. + trigger function. This information is only needed when writing + trigger functions in C. If you are using a higher-level language then + these details are handled for you. In most cases you should consider + using a procedural language before writing your triggers in C. The + documentation of each procedural language explains how to write a + trigger in that language.