pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: m.proctor@bigfoot.com
Cc: pgsql-sql@postgresql.org
Subject: Re: Recusrive Functions in 7.0.3
Date: Fri, 09 Feb 2001 22:29:19 -0500
Message-ID: <28783.981775759@sss.pgh.pa.us> (raw)
In-Reply-To: <01020920225704.05071@localhost.localdomain>
References: <01020920225704.05071@localhost.localdomain>

<plpgsql@polar-digital.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



view thread (5+ messages)  latest in thread

Message-ID: <28783.981775759@sss.pgh.pa.us>
Permalink:  ../28783.981775759@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/28783.981775759@sss.pgh.pa.us

 · 

reply

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, m.proctor@bigfoot.com
  Subject: Re: Recusrive Functions in 7.0.3
  In-Reply-To: <28783.981775759@sss.pgh.pa.us>
  References: <01020920225704.05071@localhost.localdomain> <28783.981775759@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