Thread: Recursive plpgsql function in rule

Recursive plpgsql function in rule

From
mito
Date:
I am trying to select subtree by parent id in table:

create table categories(id int,parent_id int
);

I am fetching it by recursive plpgsql function, which works well.

When i use that function as part of rule operation, i am getting ERROR:  stack depth limit exceeded.

I have tried to rewrite without recursion which cause infinite loop in rule.

Is it possible to sent dynamic structures in planer?
Or how to fetch subtree without change of table structure inside rule?

Thanks


Re: Recursive plpgsql function in rule

From
Heikki Linnakangas
Date:
mito wrote:
> I am trying to select subtree by parent id in table:
> 
> create table categories(
>     id int,
>     parent_id int
> );
> 
> I am fetching it by recursive plpgsql function, which works well.
> 
> When i use that function as part of rule operation, i am getting ERROR: 
>  stack depth limit exceeded.
> 
> I have tried to rewrite without recursion which cause infinite loop in 
> rule.
> 
> Is it possible to sent dynamic structures in planer?
> Or how to fetch subtree without change of table structure inside rule?

I didn't quite understand the issue, but as a general hint you might 
want to look at PG 8.4 beta which introduces support for recursive 
queries using the SQL standard WITH syntax. That's very useful when 
dealing with tree structures.

--   Heikki Linnakangas  EnterpriseDB   http://www.enterprisedb.com