X-Original-To: pgsql-sql@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 6733A924D88 for ; Wed, 28 May 2003 05:03:50 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193:10024]) (amavisd-new) with ESMTP id 71582-10 for ; Wed, 28 May 2003 05:03:49 -0400 (EDT) Received: from smtp.ualg.pt (smtp.ualg.pt [193.136.224.8]) by developer.postgresql.org (Postfix) with ESMTP id A8B27924D3A for ; Wed, 28 May 2003 05:03:48 -0400 (EDT) Received: from localhost (smtp.ualg.pt [127.0.0.1]) by smtp.ualg.pt (Postfix) with ESMTP id 1AEB04BCA9; Wed, 28 May 2003 10:03:43 +0100 (WEST) Received: from smtp.ualg.pt ([127.0.0.1]) by localhost (smtp.ualg.pt [127.0.0.1]) (amavisd-new, port 10024) with SMTP id 03626-07; Wed, 28 May 2003 10:03:40 +0100 (WEST) Received: from ualg.pt (corisco.uceh.ualg.pt [10.10.20.126]) by smtp.ualg.pt (Postfix) with ESMTP id 905004BB9A; Wed, 28 May 2003 10:03:40 +0100 (WEST) Message-ID: <3ED47B6E.6010209@ualg.pt> Date: Wed, 28 May 2003 10:03:42 +0100 From: Luis Sousa User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021226 Debian/1.2.1-9 X-Accept-Language: en-pt MIME-Version: 1.0 To: Stefano Vita Finzi Cc: pgsql-sql@postgresql.org Subject: Re: plpgsql recursion References: <01a601c31ef0$4a628220$0600a8c0@stefano> In-Reply-To: <01a601c31ef0$4a628220$0600a8c0@stefano> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/535 X-Sequence-Number: 13700 Can you post the recursion function that you use on this case to get out the information from the table ? Thanks, Luis Sousa Stefano Vita Finzi wrote: >Greetings! >I have a table like: > >node parent > 1 2 > 2 3 > 3 4 > >Since i traverse this table with a recursive function, i want to avoid >infinite recursion loop. I have wrote a function to check that a new record >does not create a circular dependency. The function i wrote is as follow: > >CREATE OR REPLACE FUNCTION dba_test(INTEGER,INTEGER) RETURNS TEXT AS ' > DECLARE > traversing ALIAS FOR $1; > testing ALIAS FOR $2; > t_rec RECORD; > BEGIN > FOR t_rec IN SELECT node,parent FROM dba_test WHERE parent = traversing >LOOP > IF t_rec.node = testing THEN > RETURN ''Circular''; > ELSE > PERFORM dba_test(t_rec.node,testing); > END IF; > END LOOP; > RETURN ''ok'' || testing::text; > END; >' LANGUAGE 'plpgsql'; > >I would use this function BEFORE inserting the new row. But if i try SELECT >dba_test(4,1); i don't have the result i expect. Can i you give me an hint >where am i wrong? > >Thank you! > >Stefano Vita Finzi >kluge@despammed.com > > >---------------------------(end of broadcast)--------------------------- >TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org > > > >