Received: from frithjof.reiner (a117.dialin.tuwien.ac.at [192.35.240.127]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f03H1C700629 for ; Wed, 3 Jan 2001 12:01:16 -0500 (EST) (envelope-from areiner@tph.tuwien.ac.at) Received: (qmail 1293 invoked by uid 500); 2 Jan 2001 21:31:36 -0000 From: "Albert REINER" Date: Tue, 2 Jan 2001 22:31:36 +0100 To: PostgreSQL-SQL Subject: PL/pgSQL: recursion? Message-ID: <20010102223136.A1265@frithjof> Mail-Followup-To: PostgreSQL-SQL Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Archive-Number: 200101/33 X-Sequence-Number: 694 Saluton, is there any possibility to do recursion in plpgsql-functions? Here is what I tried (I know that I can do it with a simple loop, of course; I am just curious about what one can or cannot do in plpgsql): ,----[ test-recursion ] | drop table ttt; | create table ttt | ( id int4, | pid int4 ); | | insert into ttt values (1, NULL); | insert into ttt values (2, NULL); | insert into ttt values (3, 1); | insert into ttt values (4, 1); | insert into ttt values (5, 1); | insert into ttt values (6, 2); | insert into ttt values (7, 2); | | drop function idPath(int4); | create function idPath(int4) returns text as ' | declare | str text; | str2 text; | r record; | begin | select id, pid into r from ttt where id = $1; | str := r.id::text; | if r.pid IS NOT NULL then | str2 := idPath(r.id); | str := str || '':'' || str2; | end if; | return str; | end;' language 'plpgsql'; | `---- And when I tried to use it, I got: ,---- | select idPath(5); | pqReadData() -- backend closed the channel unexpectedly. | This probably means the backend terminated abnormally | before or while processing the request. | The connection to the server was lost. Attempting reset: Failed. `---- I'm running Postgres 7.0.2. Thanks in advance, Albert. -- -------------------------------------------------------------------------- Albert Reiner Deutsch * English * Esperanto * Latine --------------------------------------------------------------------------