Re: Infinite recursion detected... How do I prevent that? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Infinite recursion detected... How do I prevent that?
Date
Msg-id 20050119143419.GE18648@svana.org
Whole thread Raw
In response to Infinite recursion detected... How do I prevent that?  (Alban Hertroys <alban@magproductions.nl>)
List pgsql-general
On Wed, Jan 19, 2005 at 02:57:47PM +0100, Alban Hertroys wrote:
> 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;

<snip>

> 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.

Sorry, RULEs are like macros, they essentially expand and transform
your original query. This also means the expansion does not depend on
the data in your database. So postgresql continaually expands the
query, leading to your infinite recursion error.

Why do you want a RULE anyway, trigger are much easier to understand.
It may be possile to setup some RULEs to avoid recursion but it won't
be easy...

Hope this helps,

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Robby Russell
Date:
Subject: Re: PostgreSQL 8.0.0 Released
Next
From: Michael Garriss
Date:
Subject: Need help recovering