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 26C7153FA5 for ; Thu, 5 May 2005 01:00:02 -0300 (ADT) 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 74804-01 for ; Thu, 5 May 2005 03:59:57 +0000 (GMT) Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id 4BC9953FE7 for ; Thu, 5 May 2005 00:59:56 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id D810C30952; Thu, 5 May 2005 05:57:58 +0200 (MET DST) From: Ezequiel Tolnay X-Newsgroups: pgsql.sql Subject: Re: Calling a stored procedure from another stored procedure... Date: Thu, 05 May 2005 13:55:51 +1000 Organization: Hub.Org Networking Services Lines: 22 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050319 X-Accept-Language: en-au, en-gb, en-us, en, es-ar, es-es In-Reply-To: To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.013 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/62 X-Sequence-Number: 21375 Christophe Geers wrote: > I came as far as getting the first returned result by performing a > SELECT INTO mytype function calculate_cost(...)...etc., which is normal > I guess since a SELECT INTO only returns a single row according to the > manual. However is there a way to loop / iterate all of the results? SELECT INTO a variable will only get the first row of the returning rowset. To get the full rowset into a temporary table, you'll have to use INSERT INTO MYTEMPTABLE SELECT * FROM MYFUNCTION(), but working with temporary tables is never very pleasing in postgresql. I recommmend you to iterate over the results by doing the following: _t := 0; FOR _myrecord IN SELECT * FROM myfunction(...) LOOP _t := _t + _myrecord.mycolumn; END LOOP; Cheers, Ezequiel Tolnay