From: Tom Lane <tgl@sss.pgh.pa.us>
To: Albert REINER <areiner@tph.tuwien.ac.at>
Cc: PostgreSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: PL/pgSQL: recursion?
Date: Wed, 03 Jan 2001 13:09:24 -0500
Message-ID: <16774.978545364@sss.pgh.pa.us> (raw)
In-Reply-To: <20010102223136.A1265@frithjof>
References: <20010102223136.A1265@frithjof>
"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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, areiner@tph.tuwien.ac.at
Subject: Re: PL/pgSQL: recursion?
In-Reply-To: <16774.978545364@sss.pgh.pa.us>
References: <20010102223136.A1265@frithjof> <16774.978545364@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox