Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 5FAEE9FB97F for ; Fri, 20 Apr 2007 15:25:52 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 18819-05 for ; Fri, 20 Apr 2007 15:25:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id 557659FB607 for ; Fri, 20 Apr 2007 15:25:48 -0300 (ADT) Received: by noel.decibel.org (Postfix, from userid 1001) id EFB74564BC; Fri, 20 Apr 2007 13:25:47 -0500 (CDT) Received: (hashcash-sendmail, from uid 1001); Fri, 20 Apr 2007 13:25:46 -0500 Date: Fri, 20 Apr 2007 13:25:46 -0500 From: "Jim C. Nasby" To: "Alexander B." Cc: "pgsql-admin@postgresql.org" Subject: Re: Return data from function Message-ID: <20070420182545.GN72669@nasby.net> References: <46251D50.2000601@yahoo.com.br> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46251D50.2000601@yahoo.com.br> X-Operating-System: FreeBSD 6.1-RELEASE-p10 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.13 (2006-08-11) X-Hashcash: 1:20:070420:burbello3000@yahoo.com.br::IjmPIrDQvRiOIe4X:000000000000 0000000000000000000000002S8y X-Hashcash: 1:20:070420:pgsql-admin@postgresql.org::4goIX0cnfNNySJAI:00000000000 00000000000000000000000017PL X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/193 X-Sequence-Number: 25257 The magic you're looking for is UNION ALL. You could just union the two address tables together and join that to the address code table, but that'll probably lead to an inefficient plan. You'll likely need to join the address code table to each address table separately, and then UNION ALL those together. On Tue, Apr 17, 2007 at 04:17:36PM -0300, 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? > > Thanks in advance. > > ---------------------------(end of broadcast)--------------------------- > TIP 6: explain analyze is your friend > -- Jim Nasby jim@nasby.net EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)