CREATE [ OR REPLACE ] RULE name AS ON event
TO table [ WHERE condition ]
- DO [ INSTEAD ] { NOTHING | command | ( command ; command ... ) }
+ DO [ ALSO | INSTEAD ] { NOTHING | command | ( command ; command ... ) }
or deletions in database tables. Roughly speaking, a rule causes
additional commands to be executed when a given command on a given
table is executed. Alternatively, an INSTEAD
- rule can replace a given command by another, or cause a command
- not to be executed at all. Rules are used to implement table
- views as well. It is important to realize that a rule is really
- a command transformation mechanism, or command macro. The
- transformation happens before the execution of the commands starts.
- If you actually want an operation that fires independently for each
- physical row, you probably want to use a trigger, not a rule.
+ rule can replace a given command by another, or cause a command
+ not to be executed at all. Rules are used to implement table
+ views as well. It is important to realize that a rule is really
+ a command transformation mechanism, or command macro. The
+ transformation happens before the execution of the commands starts.
+ If you actually want an operation that fires independently for each
+ physical row, you probably want to use a trigger, not a rule.
More information about the rules system is in .
event
- The even is one of SELECT,
+ The event is one of SELECT,
INSERT, UPDATE, or
DELETE.
condition
- Any SQL conditional expression (returning boolean).
- The condition expression may not refer to any tables except
- NEW and OLD, and may not
- contain aggregate functions.
+ Any
SQL conditional expression (returning
+ boolean). The condition expression may not refer
+ to any tables except NEW> and OLD>, and
+ may not contain aggregate functions.
INSTEAD indicates that the commands should be
- executed instead> of the original command, not in
- addition to the original command.
+ executed instead of> the original command.
+
+
+
+
+
+
+
+ ALSO indicates that the commands should be
+ executed in addition to the original
+ command.
+
+
+ If neither ALSO nor
+ INSTEAD is specified, ALSO
+ is the default.
The command or commands that make up the rule action. Valid
- commands are <literal>SELECT>,
- <literal>INSERT, UPDATE>,
- <literal>DELETE, or NOTIFY>.
+ commands are <command>SELECT>,
+ <command>INSERT, UPDATE>,
+ <command>DELETE, or NOTIFY>.
issued even if there are not any rows that the rule should apply
to. For example, in
-CREATE RULE notify_me AS ON UPDATE TO mytable DO NOTIFY mytable;
+CREATE RULE notify_me AS ON UPDATE TO mytable DO ALSO NOTIFY mytable;
UPDATE mytable SET name = 'foo' WHERE id = 42;
one NOTIFY event will be sent during the
- UPDATE, whether or not there are any rows with
- id = 42. This is an implementation restriction
- that may be fixed in future releases.
+ UPDATE, whether or not there are any rows that
+ match the condition id = 42. This is an
+ implementation restriction that may be fixed in future releases.
CREATE RULE is a
PostgreSQL language extension, as is the
- entire rules system.
+ entire query rewrite system.