X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 96A9311F7D94 for ; Mon, 10 Apr 2006 12:09:45 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: 0.669 X-Spam-Level: X-Spam-Status: No, score=0.669 required=5 tests=[AWL=0.120, FORGED_HOTMAIL_RCVD2=0.549, UPPERCASE_25_50=0] Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id Xd3ek2BiGdaj for ; Mon, 10 Apr 2006 12:09:34 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 587BE11F7CF3 for ; Mon, 10 Apr 2006 12:09:32 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 8A39F30F62; Mon, 10 Apr 2006 17:09:31 +0200 (MET DST) From: "codeWarrior" X-Newsgroups: pgsql.sql Subject: Re: Returning a set from an function Date: Mon, 10 Apr 2006 08:10:47 -0700 Organization: iDynaTECH, Inc. Lines: 65 Message-ID: References: <45435c1a0604081410o12d5a456x1fb6d09ce8973cc6@mail.gmail.com> Reply-To: "codeWarrior" X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 To: pgsql-sql@postgresql.org X-Archive-Number: 200604/61 X-Sequence-Number: 24870 Keith: This is the general approach I use over and over and over -- This is a PLPGSQL function that returns a SETOF tablename%ROWTYPE If you need the full schema and table and everything that goes with this -- let me know --- CREATE OR REPLACE FUNCTION sys_aclsubmenu(int4) RETURNS SETOF sys_tree_components AS $BODY$ DECLARE MNU ALIAS FOR $1; DECLARE OUT sys_tree_components%ROWTYPE; DECLARE CHILD sys_tree_components%ROWTYPE; BEGIN RAISE NOTICE 'sys_aclsubmenu(integer, varchar) called for item: %', $1; FOR OUT IN SELECT * FROM sys_tree_components WHERE parent = $1 AND active_flag LOOP IF (OUT.id != OUT.parent) THEN FOR CHILD IN SELECT * FROM sys_aclsubmenu(OUT.id) LOOP RETURN NEXT CHILD; END LOOP; END IF; RETURN NEXT OUT; END LOOP; RETURN; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE; SELECT * FROM sys_aclsubmenu(1) ORDER BY parent, id ; ""Keith Hutchison"" wrote in message news:45435c1a0604081410o12d5a456x1fb6d09ce8973cc6@mail.gmail.com... > G'day, > > Looking for an example showing how to return a set from either a sql > function or a plpsqq function. > > Thanks > > -- > Keith Hutchison > http://balance-infosystems.com http://realopen.org > http://www.kasamba.com/Keith-Hutchison > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings >