
But for ON UPDATE and ON DELETE rules, the original query is done after the actions added by rules.

This allows the actions to see the inserted row(s). Since only qualified INSTEAD rules already add the original query tree, we end up with either one or two output query trees for a rule with one action.įor ON INSERT rules, the original query (if not suppressed by INSTEAD) is done before any actions added by rules. The query tree from the rule action with the rule qualification and the original query tree's qualification and the original query tree with the negated rule qualification addedįinally, if the rule is ALSO, the unchanged original query tree is added to the list. The query tree from the rule action with the rule qualification and the original query tree's qualification added Qualification given and INSTEAD The query tree from the rule action with the original query tree's qualification added Qualification given and ALSO No qualification, with either ALSO or INSTEAD So we have three cases that produce the following query trees for a one-action rule. This qualification can only reference the pseudorelations NEW and/or OLD, which basically represent the relation that was given as object (but with a special meaning). What is a rule qualification? It is a restriction that tells when the actions of the rule should be done and when not. This rule can have a qualification or not and it can be INSTEAD or ALSO (the default).

To simplify, we will look at a rule with one action. There can be zero ( NOTHING key word), one, or multiple actions. For update rules, the rule system creates a list of query trees. Update rules get applied by the rule system when the result relation and the command type of a query tree are equal to the object and event given in the CREATE RULE command.

In the following, update rules means rules that are defined on INSERT, UPDATE, or DELETE.
