pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Return data from function
3+ messages / 3 participants
[nested] [flat]

* Return data from function
@ 2007-04-17 19:17  Alexander B. <burbello3000@yahoo.com.br>
  0 siblings, 2 replies; 3+ messages in thread

From: Alexander B. @ 2007-04-17 19:17 UTC (permalink / raw)
  To: pgsql-admin

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.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Return data from function
@ 2007-04-18 02:02  Robert Treat <robert@omniti.com>
  parent: Alexander B. <burbello3000@yahoo.com.br>
  1 sibling, 0 replies; 3+ messages in thread

From: Robert Treat @ 2007-04-18 02:02 UTC (permalink / raw)
  To: pgsql-admin; +Cc: Alexander B. <burbello3000@yahoo.com.br>

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/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Return data from function
@ 2007-04-20 18:25  Jim C. Nasby <jim@nasby.net>
  parent: Alexander B. <burbello3000@yahoo.com.br>
  1 sibling, 0 replies; 3+ messages in thread

From: Jim C. Nasby @ 2007-04-20 18:25 UTC (permalink / raw)
  To: Alexander B. <burbello3000@yahoo.com.br>; +Cc: pgsql-admin

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)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2007-04-20 18:25 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-04-17 19:17 Return data from function Alexander B. <burbello3000@yahoo.com.br>
2007-04-18 02:02 ` Robert Treat <robert@omniti.com>
2007-04-20 18:25 ` Jim C. Nasby <jim@nasby.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox