11<!--
2- $PostgreSQL: pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.43 2004/03/04 14:32:12 momjian Exp $
2+ $PostgreSQL: pgsql/doc/src/sgml/ref/create_rule.sgml,v 1.44 2004/03/09 19:30:21 neilc Exp $
33PostgreSQL documentation
44-->
55
@@ -22,7 +22,7 @@ PostgreSQL documentation
2222<synopsis>
2323CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS ON <replaceable class="parameter">event</replaceable>
2424 TO <replaceable class="parameter">table</replaceable> [ WHERE <replaceable class="parameter">condition</replaceable> ]
25- DO [ INSTEAD ] { NOTHING | <replaceable class="parameter">command</replaceable> | ( <replaceable class="parameter">command</replaceable> ; <replaceable class="parameter">command</replaceable> ... ) }
25+ DO [ ALSO | INSTEAD ] { NOTHING | <replaceable class="parameter">command</replaceable> | ( <replaceable class="parameter">command</replaceable> ; <replaceable class="parameter">command</replaceable> ... ) }
2626</synopsis>
2727 </refsynopsisdiv>
2828
@@ -43,13 +43,13 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS
4343 or deletions in database tables. Roughly speaking, a rule causes
4444 additional commands to be executed when a given command on a given
4545 table is executed. Alternatively, an <literal>INSTEAD</literal>
46- rule can replace a given command by another, or cause a command
47- not to be executed at all. Rules are used to implement table
48- views as well. It is important to realize that a rule is really
49- a command transformation mechanism, or command macro. The
50- transformation happens before the execution of the commands starts.
51- If you actually want an operation that fires independently for each
52- physical row, you probably want to use a trigger, not a rule.
46+ rule can replace a given command by another, or cause a command
47+ not to be executed at all. Rules are used to implement table
48+ views as well. It is important to realize that a rule is really
49+ a command transformation mechanism, or command macro. The
50+ transformation happens before the execution of the commands starts.
51+ If you actually want an operation that fires independently for each
52+ physical row, you probably want to use a trigger, not a rule.
5353 More information about the rules system is in <xref linkend="rules">.
5454 </para>
5555
@@ -111,7 +111,7 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS
111111 <term><replaceable class="parameter">event</replaceable></term>
112112 <listitem>
113113 <para>
114- The even is one of <literal>SELECT</literal>,
114+ The event is one of <literal>SELECT</literal>,
115115 <literal>INSERT</literal>, <literal>UPDATE</literal>, or
116116 <literal>DELETE</literal>.
117117 </para>
@@ -132,10 +132,10 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS
132132 <term><replaceable class="parameter">condition</replaceable></term>
133133 <listitem>
134134 <para>
135- Any SQL conditional expression (returning <type>boolean</type>).
136- The condition expression may not refer to any tables except
137- <literal>NEW</literal > and <literal>OLD</literal >, and may not
138- contain aggregate functions.
135+ Any <acronym> SQL</acronym> conditional expression (returning
136+ <type>boolean</type>). The condition expression may not refer
137+ to any tables except <literal>NEW</> and <literal>OLD</>, and
138+ may not contain aggregate functions.
139139 </para>
140140 </listitem>
141141 </varlistentry>
@@ -145,8 +145,24 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS
145145 <listitem>
146146 <para>
147147 <literal>INSTEAD</literal> indicates that the commands should be
148- executed <emphasis>instead</> of the original command, not in
149- addition to the original command.
148+ executed <emphasis>instead of</> the original command.
149+ </para>
150+ </listitem>
151+ </varlistentry>
152+
153+ <varlistentry>
154+ <term><option>ALSO</option></term>
155+ <listitem>
156+ <para>
157+ <literal>ALSO</literal> indicates that the commands should be
158+ executed <emphasis>in addition to</emphasis> the original
159+ command.
160+ </para>
161+
162+ <para>
163+ If neither <literal>ALSO</literal> nor
164+ <literal>INSTEAD</literal> is specified, <literal>ALSO</literal>
165+ is the default.
150166 </para>
151167 </listitem>
152168 </varlistentry>
@@ -156,9 +172,9 @@ CREATE [ OR REPLACE ] RULE <replaceable class="parameter">name</replaceable> AS
156172 <listitem>
157173 <para>
158174 The command or commands that make up the rule action. Valid
159- commands are <literal >SELECT</literal >,
160- <literal >INSERT</literal >, <literal >UPDATE</literal >,
161- <literal >DELETE</literal >, or <literal >NOTIFY</literal >.
175+ commands are <command >SELECT</command >,
176+ <command >INSERT</command >, <command >UPDATE</command >,
177+ <command >DELETE</command >, or <command >NOTIFY</command >.
162178 </para>
163179 </listitem>
164180 </varlistentry>
@@ -215,14 +231,14 @@ SELECT * FROM t1;
215231 issued even if there are not any rows that the rule should apply
216232 to. For example, in
217233<programlisting>
218- CREATE RULE notify_me AS ON UPDATE TO mytable DO NOTIFY mytable;
234+ CREATE RULE notify_me AS ON UPDATE TO mytable DO ALSO NOTIFY mytable;
219235
220236UPDATE mytable SET name = 'foo' WHERE id = 42;
221237</programlisting>
222238 one <command>NOTIFY</command> event will be sent during the
223- <command>UPDATE</command>, whether or not there are any rows with
224- <literal>id = 42</literal>. This is an implementation restriction
225- that may be fixed in future releases.
239+ <command>UPDATE</command>, whether or not there are any rows that
240+ match the condition <literal>id = 42</literal>. This is an
241+ implementation restriction that may be fixed in future releases.
226242 </para>
227243 </refsect1>
228244
@@ -232,7 +248,7 @@ UPDATE mytable SET name = 'foo' WHERE id = 42;
232248 <para>
233249 <command>CREATE RULE</command> is a
234250 <productname>PostgreSQL</productname> language extension, as is the
235- entire rules system.
251+ entire query rewrite system.
236252 </para>
237253 </refsect1>
238254</refentry>
0 commit comments