Create Rule
Defines a new rule on a table.
Synopsis
CREATE RULE name AS ON event TO object [ WHERE condition ] DO [ INSTEAD ] action action ::= NOTHING | query | ( query [; ...] ) | [ query [; ...] ]
Parameters
nameThe name of the new rule you are creating.
eventThe event that triggers the rule. This parameter should be one of:
SELECT,UPDATE,DELETE, orINSERT.objectThe name of a table, or the fully qualified name of a table column (e.g.,
table_name.column_name).conditionA SQL condition evaluating to a value of type
boolean, which specifies when this rule should be used. This statement should not refer to a table; the only exception to this is that the condition may refer to the specialnewandoldrelations, which represent the existing rows, and any new row data provided, respectively.INSTEADThe
INSTEADkeyword; when used, theactionis executed instead of the specifiedevent. Otherwise, theactionexecutes before theeventdoes.actionThe query (or queries) that define the action to perform when the rule is triggered, and the condition is met. The query (or queries) can be any valid
SELECT,INSERT,UPDATE,DELETE, orNOTIFYstatements. Supply multiple queries by surrounding them in parentheses.You may alternatively use the
NOTHINGkeyword instead of a query.NOTHINGwill perform no action, and is only useful if you also specify theINSTEADkeyword.
Within the condition and action values, you are able to use the special new
and old relations to access column values from both the referenced ...