Re: PL/pgSQL: recursion? - Mailing list pgsql-sql

From Tom Lane
Subject Re: PL/pgSQL: recursion?
Date
Msg-id 16774.978545364@sss.pgh.pa.us
Whole thread Raw
In response to PL/pgSQL: recursion?  ("Albert REINER" <areiner@tph.tuwien.ac.at>)
List pgsql-sql
"Albert REINER" <areiner@tph.tuwien.ac.at> writes:
> is there any possibility to do recursion in plpgsql-functions?

Recursion works fine ... but an infinite recursion, such as you have
here, will quickly overflow the available stack space and cause the
backend to crash.  You're invoking idPath with the same argument it
was passed, no?

I changed
> |     str2 := idPath(r.id);
to
> |     str2 := idPath(r.id-1);
and got

regression=# select idPath(5);idpath
---------5:4:3:2
(1 row)

which may or may not be the answer you wanted, but it does demonstrate
that a plpgsql function can recurse.
        regards, tom lane


pgsql-sql by date:

Previous
From: "Francis Solomon"
Date:
Subject: RE: order by day or month, etc
Next
From: Michael Davis
Date:
Subject: Numeric and money