~ubuntu-branches/ubuntu/precise/postgresql-9.1/precise-security

« back to all changes in this revision

Viewing changes to doc/src/sgml/html/functions-trigger.html

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
2
<HTML
 
3
><HEAD
 
4
><TITLE
 
5
>Trigger Functions</TITLE
 
6
><META
 
7
NAME="GENERATOR"
 
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
 
9
REV="MADE"
 
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
 
11
REL="HOME"
 
12
TITLE="PostgreSQL 9.1beta1 Documentation"
 
13
HREF="index.html"><LINK
 
14
REL="UP"
 
15
TITLE="Functions and Operators"
 
16
HREF="functions.html"><LINK
 
17
REL="PREVIOUS"
 
18
TITLE="System Administration Functions"
 
19
HREF="functions-admin.html"><LINK
 
20
REL="NEXT"
 
21
TITLE="Type Conversion"
 
22
HREF="typeconv.html"><LINK
 
23
REL="STYLESHEET"
 
24
TYPE="text/css"
 
25
HREF="stylesheet.css"><META
 
26
HTTP-EQUIV="Content-Type"
 
27
CONTENT="text/html; charset=ISO-8859-1"><META
 
28
NAME="creation"
 
29
CONTENT="2011-04-27T21:20:33"></HEAD
 
30
><BODY
 
31
CLASS="SECT1"
 
32
><DIV
 
33
CLASS="NAVHEADER"
 
34
><TABLE
 
35
SUMMARY="Header navigation table"
 
36
WIDTH="100%"
 
37
BORDER="0"
 
38
CELLPADDING="0"
 
39
CELLSPACING="0"
 
40
><TR
 
41
><TH
 
42
COLSPAN="5"
 
43
ALIGN="center"
 
44
VALIGN="bottom"
 
45
><A
 
46
HREF="index.html"
 
47
>PostgreSQL 9.1beta1 Documentation</A
 
48
></TH
 
49
></TR
 
50
><TR
 
51
><TD
 
52
WIDTH="10%"
 
53
ALIGN="left"
 
54
VALIGN="top"
 
55
><A
 
56
TITLE="System Administration Functions"
 
57
HREF="functions-admin.html"
 
58
ACCESSKEY="P"
 
59
>Prev</A
 
60
></TD
 
61
><TD
 
62
WIDTH="10%"
 
63
ALIGN="left"
 
64
VALIGN="top"
 
65
><A
 
66
TITLE="Functions and Operators"
 
67
HREF="functions.html"
 
68
>Fast Backward</A
 
69
></TD
 
70
><TD
 
71
WIDTH="60%"
 
72
ALIGN="center"
 
73
VALIGN="bottom"
 
74
>Chapter 9. Functions and Operators</TD
 
75
><TD
 
76
WIDTH="10%"
 
77
ALIGN="right"
 
78
VALIGN="top"
 
79
><A
 
80
TITLE="Functions and Operators"
 
81
HREF="functions.html"
 
82
>Fast Forward</A
 
83
></TD
 
84
><TD
 
85
WIDTH="10%"
 
86
ALIGN="right"
 
87
VALIGN="top"
 
88
><A
 
89
TITLE="Type Conversion"
 
90
HREF="typeconv.html"
 
91
ACCESSKEY="N"
 
92
>Next</A
 
93
></TD
 
94
></TR
 
95
></TABLE
 
96
><HR
 
97
ALIGN="LEFT"
 
98
WIDTH="100%"></DIV
 
99
><DIV
 
100
CLASS="SECT1"
 
101
><H1
 
102
CLASS="SECT1"
 
103
><A
 
104
NAME="FUNCTIONS-TRIGGER"
 
105
>9.25. Trigger Functions</A
 
106
></H1
 
107
><P
 
108
>      Currently <SPAN
 
109
CLASS="PRODUCTNAME"
 
110
>PostgreSQL</SPAN
 
111
> provides one built in trigger
 
112
      function, <CODE
 
113
CLASS="FUNCTION"
 
114
>suppress_redundant_updates_trigger</CODE
 
115
>,
 
116
      which will prevent any update
 
117
      that does not actually change the data in the row from taking place, in
 
118
      contrast to the normal behavior which always performs the update
 
119
      regardless of whether or not the data has changed. (This normal behavior
 
120
      makes updates run faster, since no checking is required, and is also
 
121
      useful in certain cases.)
 
122
    </P
 
123
><P
 
124
>      Ideally, you should normally avoid running updates that don't actually
 
125
      change the data in the record. Redundant updates can cost considerable
 
126
      unnecessary time, especially if there are lots of indexes to alter,
 
127
      and space in dead rows that will eventually have to be vacuumed.
 
128
      However, detecting such situations in client code is not
 
129
      always easy, or even possible, and writing expressions to detect
 
130
      them can be error-prone. An alternative is to use
 
131
      <CODE
 
132
CLASS="FUNCTION"
 
133
>suppress_redundant_updates_trigger</CODE
 
134
>, which will skip
 
135
      updates that don't change the data. You should use this with care,
 
136
      however. The trigger takes a small but non-trivial time for each record,
 
137
      so if most of the records affected by an update are actually changed,
 
138
      use of this trigger will actually make the update run slower.
 
139
    </P
 
140
><P
 
141
>      The <CODE
 
142
CLASS="FUNCTION"
 
143
>suppress_redundant_updates_trigger</CODE
 
144
> function can be
 
145
      added to a table like this:
 
146
</P><PRE
 
147
CLASS="PROGRAMLISTING"
 
148
>CREATE TRIGGER z_min_update
 
149
BEFORE UPDATE ON tablename
 
150
FOR EACH ROW EXECUTE PROCEDURE suppress_redundant_updates_trigger();</PRE
 
151
><P>
 
152
      In most cases, you would want to fire this trigger last for each row.
 
153
      Bearing in mind that triggers fire in name order, you would then
 
154
      choose a trigger name that comes after the name of any other trigger
 
155
      you might have on the table.
 
156
    </P
 
157
><P
 
158
>       For more information about creating triggers, see
 
159
        <A
 
160
HREF="sql-createtrigger.html"
 
161
>CREATE TRIGGER</A
 
162
>.
 
163
    </P
 
164
></DIV
 
165
><DIV
 
166
CLASS="NAVFOOTER"
 
167
><HR
 
168
ALIGN="LEFT"
 
169
WIDTH="100%"><TABLE
 
170
SUMMARY="Footer navigation table"
 
171
WIDTH="100%"
 
172
BORDER="0"
 
173
CELLPADDING="0"
 
174
CELLSPACING="0"
 
175
><TR
 
176
><TD
 
177
WIDTH="33%"
 
178
ALIGN="left"
 
179
VALIGN="top"
 
180
><A
 
181
HREF="functions-admin.html"
 
182
ACCESSKEY="P"
 
183
>Prev</A
 
184
></TD
 
185
><TD
 
186
WIDTH="34%"
 
187
ALIGN="center"
 
188
VALIGN="top"
 
189
><A
 
190
HREF="index.html"
 
191
ACCESSKEY="H"
 
192
>Home</A
 
193
></TD
 
194
><TD
 
195
WIDTH="33%"
 
196
ALIGN="right"
 
197
VALIGN="top"
 
198
><A
 
199
HREF="typeconv.html"
 
200
ACCESSKEY="N"
 
201
>Next</A
 
202
></TD
 
203
></TR
 
204
><TR
 
205
><TD
 
206
WIDTH="33%"
 
207
ALIGN="left"
 
208
VALIGN="top"
 
209
>System Administration Functions</TD
 
210
><TD
 
211
WIDTH="34%"
 
212
ALIGN="center"
 
213
VALIGN="top"
 
214
><A
 
215
HREF="functions.html"
 
216
ACCESSKEY="U"
 
217
>Up</A
 
218
></TD
 
219
><TD
 
220
WIDTH="33%"
 
221
ALIGN="right"
 
222
VALIGN="top"
 
223
>Type Conversion</TD
 
224
></TR
 
225
></TABLE
 
226
></DIV
 
227
></BODY
 
228
></HTML
 
229
>
 
 
b'\\ No newline at end of file'