1
1
<!--
2
- $PostgreSQL: pgsql/doc/src/sgml/ref/create_trigger.sgml,v 1.50 2009/09/19 10:23:27 petere Exp $
2
+ $PostgreSQL: pgsql/doc/src/sgml/ref/create_trigger.sgml,v 1.51 2009/10/14 22:14:21 tgl Exp $
3
3
PostgreSQL documentation
4
4
-->
5
5
@@ -49,7 +49,7 @@ CREATE TRIGGER <replaceable class="PARAMETER">name</replaceable> { BEFORE | AFTE
49
49
current row, or change the row being inserted (for
50
50
<command>INSERT</command> and <command>UPDATE</command> operations
51
51
only). If the trigger fires after the event, all changes, including
52
- the last insertion, update, or deletion , are <quote>visible</quote>
52
+ the effects of other triggers , are <quote>visible</quote>
53
53
to the trigger.
54
54
</para>
55
55
@@ -122,6 +122,16 @@ CREATE TRIGGER <replaceable class="PARAMETER">name</replaceable> { BEFORE | AFTE
122
122
this specifies the event that will fire the trigger. Multiple
123
123
events can be specified using <literal>OR</literal>.
124
124
</para>
125
+
126
+ <para>
127
+ For <command>UPDATE</command> triggers, it is possible to
128
+ specify a list of columns using this syntax:
129
+ <synopsis>
130
+ UPDATE OF <replaceable>column_name1</replaceable> [, <replaceable>column_name2</replaceable> ... ]
131
+ </synopsis>
132
+ The trigger will only fire if at least one of the listed columns
133
+ is mentioned as a target of the update.
134
+ </para>
125
135
</listitem>
126
136
</varlistentry>
127
137
@@ -169,8 +179,8 @@ CREATE TRIGGER <replaceable class="PARAMETER">name</replaceable> { BEFORE | AFTE
169
179
literal string constants. Simple names and numeric constants
170
180
can be written here, too, but they will all be converted to
171
181
strings. Please check the description of the implementation
172
- language of the trigger function about how the trigger arguments
173
- are accessible within the function; it might be different from
182
+ language of the trigger function to find out how these arguments
183
+ can be accessed within the function; it might be different from
174
184
normal function arguments.
175
185
</para>
176
186
</listitem>
@@ -191,6 +201,18 @@ CREATE TRIGGER <replaceable class="PARAMETER">name</replaceable> { BEFORE | AFTE
191
201
endterm="sql-droptrigger-title"> to remove a trigger.
192
202
</para>
193
203
204
+ <para>
205
+ A column-specific trigger (<literal>FOR UPDATE OF
206
+ <replaceable>column_name</replaceable></literal>) will fire when any
207
+ of its columns are listed as targets in the <command>UPDATE</>
208
+ command's <literal>SET</> list. It is possible for a column's value
209
+ to change even when the trigger is not fired, because changes made to the
210
+ row's contents by <literal>BEFORE UPDATE</> triggers are not considered.
211
+ Conversely, a command such as <literal>UPDATE ... SET x = x ...</>
212
+ will fire a trigger on column <literal>x</>, even though the column's
213
+ value did not change.
214
+ </para>
215
+
194
216
<para>
195
217
In <productname>PostgreSQL</productname> versions before 7.3, it was
196
218
necessary to declare trigger functions as returning the placeholder
@@ -218,13 +240,6 @@ CREATE TRIGGER <replaceable class="PARAMETER">name</replaceable> { BEFORE | AFTE
218
240
<acronym>SQL</> standard. The following functionality is currently missing:
219
241
220
242
<itemizedlist>
221
- <listitem>
222
- <para>
223
- SQL allows triggers to fire on updates to specific columns
224
- (e.g., <literal>AFTER UPDATE OF col1, col2</literal>).
225
- </para>
226
- </listitem>
227
-
228
243
<listitem>
229
244
<para>
230
245
SQL allows you to define aliases for the <quote>old</quote>
@@ -264,9 +279,10 @@ CREATE TRIGGER <replaceable class="PARAMETER">name</replaceable> { BEFORE | AFTE
264
279
The <productname>PostgreSQL</productname> behavior is for <literal>BEFORE
265
280
DELETE</literal> to always fire before the delete action, even a cascading
266
281
one. This is considered more consistent. There is also unpredictable
267
- behavior when <literal>BEFORE</literal> triggers modify rows that are later
268
- to be modified by referential actions. This can lead to constraint violations
269
- or stored data that does not honor the referential constraint.
282
+ behavior when <literal>BEFORE</literal> triggers modify rows or prevent
283
+ updates during an update that is caused by a referential action. This can
284
+ lead to constraint violations or stored data that does not honor the
285
+ referential constraint.
270
286
</para>
271
287
272
288
<para>
0 commit comments