Re: Creating a PL/pgSQL function that returns multiple out parameters and refcursor

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Néstor Boscán <nestorjb(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: Creating a PL/pgSQL function that returns multiple out parameters and refcursor
Date: 2014-10-03 04:40:19
Message-ID: CAB7nPqTeJ7nMOPVZFzBeYnMDdHDot3nNp0sHgB5-9QNDZgKnZg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Oct 3, 2014 at 1:15 AM, Néstor Boscán <nestorjb(at)gmail(dot)com> wrote:
> 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2014-10-03 06:28:57 Re: How to find greatest record before known values fast
Previous Message Steve Atkins 2014-10-03 04:12:05 Re: installing on mac air development machine