Skip site navigation (1) Skip section navigation (2)

Re: JOIN results of refcursor functions

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Milan Oparnica <milan(dot)opa(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: JOIN results of refcursor functions
Date: 2008-12-01 02:08:46
Message-ID: 20081201020846.GB5632@alvh.no-ip.org (view raw or flat)
Thread:
Lists: pgsql-sql
Milan Oparnica escribió:

> I've searched documentation (8.3) and didn't find a way to use OUT  
> variables in same manner as SETOF (RETURN NEXT doesn't create a record  
> type result).
>
> Can you please give an example of how to return select fld1, fld2 from  
> table through OUT variables so the caller gets records ?

create function foo (a int, out b int, out c text) returns setof record language plpgsql as $$      
begin                                                                                               
b = 2 * a;                                                                                          
c = 'dos por a';                                                                                    
return next;                                                                                        
b = 3 * a;                                                                                          
c = 'tres por a';                                                                                   
return next;                                                                                        
end; $$ ;                                                                                           
                                                                                                    
alvherre=# select * from foo(4);                                                                    
 b  |     c                                                                                         
----+------------                                                                                   
  8 | dos por a                                                                                     
 12 | tres por a                                                                                    
(2 filas)                                                                                           

I guess you should be able to do the same with cursor operations.  I
haven't seen how you use refcursor in a plpgsql function.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

In response to

Responses

pgsql-sql by date

Next:From: John DizaroDate: 2008-12-01 16:25:23
Subject: how to update 400 000 register not at the same time?
Previous:From: Milan OparnicaDate: 2008-11-30 23:13:44
Subject: Re: JOIN results of refcursor functions

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group