Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id E8FB59FA1BF for ; Wed, 18 Apr 2007 00:14:55 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 35324-02 for ; Wed, 18 Apr 2007 00:14:35 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from vms048pub.verizon.net (vms048pub.verizon.net [206.46.252.48]) by postgresql.org (Postfix) with ESMTP id 4B6C59FB59E for ; Wed, 18 Apr 2007 00:02:46 -0300 (ADT) Received: from new-host.home ([71.166.59.121]) by vms048.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JGO00H2C8C16XH1@vms048.mailsrvcs.net> for pgsql-admin@postgresql.org; Tue, 17 Apr 2007 21:02:25 -0500 (CDT) Date: Tue, 17 Apr 2007 22:02:22 -0400 From: Robert Treat Subject: Re: Return data from function In-reply-to: <46251D50.2000601@yahoo.com.br> To: pgsql-admin@postgresql.org Cc: "Alexander B." Message-id: <200704172202.22873.robert@omniti.com> Organization: OmniTI MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-transfer-encoding: 7bit Content-disposition: inline References: <46251D50.2000601@yahoo.com.br> User-Agent: KMail/1.9.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/199 X-Sequence-Number: 25263 On Tuesday 17 April 2007 15:17, Alexander B. wrote: > Hello, > > I need to create a function that find data over 3 tables, merge and > return data. > With example can be specified more clearly: > > 1.1 Find all addresses code; > 1.2 For each addresses code, get address, complement and city on the > first table; > 1.3 For each addresses code, get address, complement and city on the > second table; > 1.4 Merge result from first and second tables and return to the function; > > I would like to do not using cursor. > Do you have any ideas how to implement? > I'm not convinced you can't do this from plain sql, but if you're sure a function is the way to go, see the docs on set returning functions: http://www.postgresql.org/docs/current/static/xfunc-sql.html#XFUNC-SQL-TABLE-FUNCTIONS -- Robert Treat Database Architect http://www.omniti.com/