X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 64C0D3A530D for ; Mon, 22 Nov 2004 19:39:31 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47567-05 for ; Mon, 22 Nov 2004 19:39:25 +0000 (GMT) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.203]) by svr1.postgresql.org (Postfix) with ESMTP id 2ADCB3A5203 for ; Mon, 22 Nov 2004 19:39:25 +0000 (GMT) Received: by rproxy.gmail.com with SMTP id a36so236735rnf for ; Mon, 22 Nov 2004 11:39:21 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=er/iLyG3l9Te6Tv9qC9fyS6q+iFNAQxfzps4RaeKqKJzW6ys7pZwYGUupXd27ThGdvU24zMan0jlcjClX2gYTMR+59v/NNhN7StBF7NTuqEXrf4tHdY6Do9XsR9E6n0jU3s9qXdSlRFt4B+4Qws+oUWCUd8/b54pA6uiaV7iY84= Received: by 10.38.126.2 with SMTP id y2mr991643rnc; Mon, 22 Nov 2004 11:39:21 -0800 (PST) Received: by 10.38.126.17 with HTTP; Mon, 22 Nov 2004 11:39:21 -0800 (PST) Message-ID: Date: Mon, 22 Nov 2004 14:39:21 -0500 From: Mike Rylander Reply-To: Mike Rylander To: Richard Rowell Subject: Re: [postgres] Re: Recursive SETOF function Cc: pgsql-sql@postgresql.org In-Reply-To: <1101149501.18148.81.camel@richard> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <1101136693.18148.66.camel@richard> <1101149501.18148.81.camel@richard> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200411/236 X-Sequence-Number: 19555 Sorry about that... try this: CREATE OR REPLACE FUNCTION svp_getparentproviderids (INTEGER) RETURNS SETOF svp_getparentproviderids_uid_type AS ' DECLARE child_provider ALIAS FOR $1; cid svp_getparentproviderids_uid_type%ROWTYPE; tmp_cid INTEGER; BEGIN SELECT INTO tmp_cid count(*) FROM providers WHERE uid =child_provider; IF tmp_cid = 0 THEN RAISE EXCEPTION ''Inexistent ID --> %'', child_provider; RETURN; END IF; cid.uid := child_provider; LOOP EXIT WHEN tmp_cid IS NULL; RETURN NEXT cid; SELECT INTO tmp_cid parent_id FROM providers WHERE uid=cid.uid; END LOOP; RETURN; END;' LANGUAGE 'plpgsql'; On Mon, 22 Nov 2004 12:51:41 -0600, Richard Rowell wrote: > I have been fiddling with what you sent. I have it working mostly, save > for I keep getting syntax errors on the "RETURN NEXT cid;" line. If I > remove this line then the function works ( but returns nothing of > course). Any ideas? > > sp_demo_505=# CREATE OR REPLACE FUNCTION svp_getparentproviderids > (INTEGER) > RETURNS SETOF svp_getparentproviderids_uid_type > AS ' > DECLARE > child_provider ALIAS FOR $1; > cid INTEGER; > BEGIN > SELECT INTO cid count(*) FROM providers WHERE uid =child_provider; > IF cid = 0 THEN > RAISE EXCEPTION ''Inexistent ID --> %'', child_provider; > RETURN; > END IF; > cid := child_provider; > LOOP > EXIT WHEN cid IS NULL; > RETURN NEXT cid; > SELECT INTO cid parent_id FROM providers WHERE uid=cid; > END LOOP; > RETURN; > END;' LANGUAGE 'plpgsql'; > CREATE FUNCTION > sp_demo_505=# select * from svp_getparentproviderids(21112); > ERROR: incorrect argument to RETURN NEXT at or near "cid" > CONTEXT: compile of PL/pgSQL function "svp_getparentproviderids" near > line 13 > > -- Mike Rylander mrylander@gmail.com GPLS -- PINES Development Database Developer