Re: PL/pgSQL: recursion?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Albert REINER" <areiner(at)tph(dot)tuwien(dot)ac(dot)at>
Cc: PostgreSQL-SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: PL/pgSQL: recursion?
Date: 2001-01-03 18:09:24
Message-ID: 16774.978545364@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Albert REINER" <areiner(at)tph(dot)tuwien(dot)ac(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Davis 2001-01-03 18:11:36 Numeric and money
Previous Message Francis Solomon 2001-01-03 18:04:14 RE: order by day or month, etc