I have a rule similar to this:

CREATE RULE rule_branch_delete AS
ON DELETE TO tree
DO DELETE
     FROM tree
    WHERE ancestor_id IS NOT NULL
      AND OLD.child_id = ancestor_id;

The data is oraganized like this:

ancestor_id     child_id
================================
NULL            1
1               2
1               3
1               4
1               5
1               6
1               7
1               8
2               4
2               5
2               6
3               7
3               8
etc.

This is an optimization table that relates all nodes in a branch to all it's ancestor nodes; to it's parent, to it's grand parent to it's grand grand parent, etc.

The tree is 3 to 5 levels deep. The intention is to delete all children of a branch that share the same ancestor when an ancestor gets deleted. This happens recursively, of course.

If I try a delete on the tree table I get "Infinite recursion detected on rules on tree". I'm pretty sure it's not "infinite" in my case, how can I make it delete the records regardless this "infinity"?

At the moment I use a trigger, but I would prefer a rule.

Alban.

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
   (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to