Skip site navigation (1) Skip section navigation (2)

Postgres and recursion

From: glenn <vmstech(at)tpg(dot)com(dot)au>
To: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Postgres and recursion
Date: 2003-02-27 03:16:39
Message-ID: 1046315799.9243.12.camel@thor.valhalla (view raw or flat)
Lists: pgsql-novice
Hi all
How well does postgres handle recursion?
I've got this simple function which climbs up a 'selfjoin' tree called
job, and reports back the id of the root of the tree. It seemed to work
in 7.2 (which I'm told doesn't recurse???), but I've just upgraded to
7.3.2 (i.e debians latest) and when I execute it, the server kicks me
off, like so:

vmspj=# select fx_root_job(2);
server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

Should I abandon this approach altogether?

create or replace function fx_root_job(int4) returns int4 as '

        x int4;
        returnvalue int4;
        select into x id_parent_ from job
                where id_ = $1;
        if x = $1 or x = 0 then
                returnvalue = $1;
                returnvalue = fx_root_job( x );
        end if;
        return returnvalue;
end;' language 'plpgsql';


pgsql-novice by date

Next:From: Tom LaneDate: 2003-02-27 06:46:04
Subject: Re: Postgres and recursion
Previous:From: Chad ThompsonDate: 2003-02-25 18:48:51
Subject: Re: pq_flush: send() failed: Broken pipe

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group