Contents /
Previous /
Next
Rules
Rules allow actions to take place when a table is accessed. In this
way, they can modify the effects of SELECT, INSERT, UPDATE, and
DELETE.
CREATE RULE name AS ON event
TO object [ WHERE condition ]
DO [ INSTEAD ] action
where action can be:
NOTHING
|
query
|
( query ; query ... )
|
[ query ; query ... ]
Example "a rule that prevents INSERTs into a table":
CREATE TABLE ruletest (col INTEGER);
CREATE RULE ruletest_insert AS -- rule name
ON INSERT TO ruletest -- INSERT rule
DO INSTEAD -- DO INSTEAD-type rule
NOTHING ; -- ACTION is NOTHING
The INSERT rule is named ruletest_insert and the action is
NOTHING. NOTHING is a special rule keyword that does nothing.
Two types of rules exist. DO rules perform SQL commands in addition to
the submitted query. DO INSTEAD rules replace the user query with the
rule action.
Example "age check for kids":
CREATE RULE rule_test AS ON INSERT TO stud_childs
DO DELETE FROM stud_childs WHERE age < 5 ;