X-Original-To: pgsql-sql@postgresql.org Received: from localhost (unknown [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id B8CBC925FF3 for ; Fri, 23 May 2003 01:29:29 -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 56530-06 for ; Fri, 23 May 2003 01:28:57 -0400 (EDT) Received: from tomts10-srv.bellnexxia.net (tomts10.bellnexxia.net [209.226.175.54]) by developer.postgresql.org (Postfix) with ESMTP id 2FC19925FFA for ; Thu, 22 May 2003 21:59:44 -0400 (EDT) Received: from [192.168.1.200] ([64.231.213.3]) by tomts10-srv.bellnexxia.net (InterMail vM.5.01.05.32 201-253-122-126-132-20030307) with ESMTP id <20030523015943.GILC24981.tomts10-srv.bellnexxia.net@[192.168.1.200]>; Thu, 22 May 2003 21:59:43 -0400 Subject: Re: plpgsql recursion From: Rod Taylor To: Stefano Vita Finzi Cc: pgsql-sql@postgresql.org In-Reply-To: <01a601c31ef0$4a628220$0600a8c0@stefano> References: <01a601c31ef0$4a628220$0600a8c0@stefano> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-f03Racm8FhpcxGKjvoV1" Organization: Message-Id: <1053655182.279.28.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Date: 22 May 2003 21:59:43 -0400 X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/451 X-Sequence-Number: 13616 --=-f03Racm8FhpcxGKjvoV1 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > IF t_rec.node =3D testing THEN > RETURN ''Circular''; > ELSE > PERFORM dba_test(t_rec.node,testing); > END IF; > I would use this function BEFORE inserting the new row. But if i try SELE= CT > dba_test(4,1); i don't have the result i expect. Can i you give me an hint > where am i wrong? It's probably working as it's written :) Once it finds 'Curcular' and returns it to the recursed call of dba_test, you immediately throw away the return value. PERFORM should probably be replaced with: ELSE -- ret is a variable SELECT dba_test(t_rec.node, testing) INTO ret; IF ret =3D ''Circular'' THEN RETURN ret; END IF; END IF; More to the point, if you're attempting to prevent circular items, and this function will be used in the form of a trigger, then simply RAISE EXCEPTION. This way you can ignore having to deal with returned values. --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-f03Racm8FhpcxGKjvoV1 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQA+zYCO6DETLow6vwwRAvcpAJ9tym7I+fEnJmXnFozhAbbM02b9rwCfdqVY eUK0ccIBcmlZVtYyJsdmHys= =TuMS -----END PGP SIGNATURE----- --=-f03Racm8FhpcxGKjvoV1--