| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | m(dot)proctor(at)bigfoot(dot)com |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Recusrive Functions in 7.0.3 |
| Date: | 2001-02-10 03:29:19 |
| Message-ID: | 28783.981775759@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
<plpgsql(at)polar-digital(dot)com> writes:
> Are recursive functions allowed in in 7.0.3
Sure.
play=> create function myfactorial(int) returns int as '
play'> begin
play'> if $1 > 1 then
play'> return $1 * myfactorial($1 - 1);
play'> end if;
play'> return $1;
play'> end;' language 'plpgsql';
CREATE
play=> select myfactorial(1);
myfactorial
-------------
1
(1 row)
play=> select myfactorial(10);
myfactorial
-------------
3628800
(1 row)
play=>
I get a stack overflow crash at about myfactorial(7500), but that seems
like a sufficient level of recursion depth for normal purposes ...
> as I seem to be unable to
> get them to work in plpgsql,
Are you sure you aren't asking for infinite recursion, eg by invoking
the same function with the same argument?
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2001-02-10 08:42:11 | Re: Recusrive Functions in 7.0.3 |
| Previous Message | guard | 2001-02-10 01:54:00 | how to download postgresql 7.1 beta |