1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.13 2000/04/07 17:37:24 momjian Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.14 2000/04/07 19: 17:30 momjian Exp $
3
3
Postgres documentation
4
4
-->
5
5
@@ -126,16 +126,17 @@ CREATE
126
126
<para>
127
127
The <productname>Postgres</productname>
128
128
<firstterm>rule system</firstterm> allows one to define an
129
- alternate action to be performed on updates, inserts , or deletions
129
+ alternate action to be performed on inserts, updates , or deletions
130
130
from database tables or classes. Currently, rules are used to
131
131
implement table views.
132
132
</para>
133
133
134
134
<para>
135
135
The semantics of a rule is that at the time an individual instance is
136
- accessed, updated, inserted or deleted, there is a current instance (for
137
- retrieves, updates and deletes) and a new instance (for updates and
138
- appends). If the <replaceable class="parameter">event</replaceable>
136
+ accessed, inserted, updated, or deleted, there is a current instance (for
137
+ selects, updates and deletes) and a new instance (for inserts and
138
+ updates).
139
+ If the <replaceable class="parameter">event</replaceable>
139
140
specified in the ON clause and the
140
141
<replaceable class="parameter">condition</replaceable> specified in the
141
142
WHERE clause are true for the current instance, the
@@ -162,8 +163,8 @@ CREATE
162
163
<para>
163
164
A caution about SQL rules is in order. If the same class name
164
165
or instance variable appears in the
165
- <replaceable class="parameter">event</replaceable>, the
166
- <replaceable class="parameter">condition</replaceable> and the
166
+ <replaceable class="parameter">event</replaceable>,
167
+ <replaceable class="parameter">condition</replaceable> and
167
168
<replaceable class="parameter">action</replaceable> parts of a rule,
168
169
they are all considered different tuple variables. More accurately,
169
170
<literal>new</literal> and <literal>current</literal> are the only tuple
@@ -172,13 +173,13 @@ CREATE
172
173
<programlisting>
173
174
ON UPDATE TO emp.salary WHERE emp.name = "Joe"
174
175
DO
175
- UPDATE emp ( ... ) WHERE ...
176
+ UPDATE emp SET ... WHERE ...
176
177
</programlisting>
177
178
178
179
<programlisting>
179
180
ON UPDATE TO emp-1.salary WHERE emp-2.name = "Joe"
180
181
DO
181
- UPDATE emp-3 ( ... ) WHERE ...
182
+ UPDATE emp-3 SET ... WHERE ...
182
183
</programlisting>
183
184
184
185
Each rule can have the optional tag INSTEAD.
@@ -194,11 +195,12 @@ ON UPDATE TO emp-1.salary WHERE emp-2.name = "Joe"
194
195
<literal>NOTHING</literal>.
195
196
</para>
196
197
<para>
197
- It is very important to note that the rewrite rule system
198
- will neither detect nor process circular rules. For example, though each
198
+ It is very important to note to avoid circular rules.
199
+ For example, though each
199
200
of the following two rule definitions are accepted by
200
201
<productname>Postgres</productname>, the
201
- retrieve command will cause <productname>Postgres</productname> to crash:
202
+ select command will cause <productname>Postgres</productname> to
203
+ report an error because the query cycled too many times:
202
204
203
205
<example>
204
206
<title>Example of a circular rewrite rule combination.</title>
@@ -216,8 +218,9 @@ CREATE RULE bad_rule_combination_2 AS
216
218
SELECT TO emp;
217
219
</programlisting>
218
220
<para>
219
- This attempt to retrieve from EMP will cause
220
- <productname>Postgres</productname> to crash.
221
+ This attempt to select from EMP will cause
222
+ <productname>Postgres</productname> to issue an error
223
+ because the queries cycled too many times.
221
224
<programlisting>
222
225
SELECT * FROM emp;
223
226
</programlisting></para>
@@ -306,7 +309,7 @@ CREATE toyemp(name = char16, salary = int4);
306
309
CREATE RULE example_4 AS
307
310
ON SELECT TO toyemp
308
311
DO INSTEAD
309
- SELECT ( emp.name, emp.salary)
312
+ SELECT emp.name, emp.salary
310
313
FROM emp
311
314
WHERE emp.dept = "toy";
312
315
</programlisting>
@@ -317,7 +320,7 @@ CREATE RULE example_4 AS
317
320
CREATE RULE example_5 AS
318
321
ON INERT TO emp WHERE new.salary > 5000
319
322
DO
320
- UPDATE NEWSET salary = 5000;
323
+ UPDATE NEWSET SET salary = 5000;
321
324
</programlisting>
322
325
</para>
323
326
</refsect1>
0 commit comments