Discussion:
Creating a PL/pgSQL function that returns multiple out parameters and refcursor
Néstor Boscán
2014-10-02 16:15:46 UTC
Permalink
Hi

Ho do I create a PL/pgSQL function that returns multiple out parameters and
a refcursor. Something like this:

create function myfunction(p_cursor out refcursor, p_code out varchar,
p_message out varchar) returns record as $$
begin
open p_cursor is select * from table;

p_code := 'OK';
p_message := 'message';

return ???
end;
$$ language plpgsql;
Michael Paquier
2014-10-03 04:40:19 UTC
Permalink
Post by Néstor Boscán
Ho do I create a PL/pgSQL function that returns multiple out parameters and
a refcursor.
Using a plain "RETURN;" is just but fine, your output parameters are
being set internally in the function:
=# create function myfunction(id_base in int, id1 out int, id2 out varchar)
returns record as $$
begin
id1 := id_base * 2;
id2 := id_base * 3;
return;
end;
$$ language plpgsql;
CREATE FUNCTION
=# select * from myfunction(3);
id1 | id2
-----+-----
6 | 9
(1 row)
=# select * from myfunction(4);
id1 | id2
-----+-----
8 | 12
(1 row)

Regards,
--
Michael
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Loading...