How to create a function with multiple RefCursor OUT parameters

From: Chuck Bai <cbai22(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How to create a function with multiple RefCursor OUT parameters
Date: 2008-05-11 18:43:23
Message-ID: 48273E4B.4050104@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have the following function:

CREATE OR REPLACE FUNCTION test_refcursor(INOUT tcount integer, OUT
o_user refcursor, OUT o_name refcursor)
RETURNS record AS
$BODY$
BEGIN
tcount := tcount + 1;
OPEN o_user FOR SELECT * FROM user_table;
OPEN o_name FOR SELECT * FROM name_table;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE

Question 1: The function is not working with Npgsql .NET data provider.
It did not return a valid .NET DataSet. But the INOUT parameter tcount
works fine. How could I test the above function with SQL in pgAdmin III?
I want to find out if problem is in the function or in the Npgsql.

Question 2: pgAdmin III automatically added "RETURNS record" in the
above function when RETURNS clause is not specified initially. Why is
that? Is this the problem since it returns only single data table with
the following value? How to fix it?

tcount o_user o_name
23 <unnamed portal 1> <unnamed portal 2>

Question 3: I want to return a single DataSet with each OUT RefCursor
map to a DataTable within the DataSet, plus extra OUT parameters for
individual OUT values. How could I create such a function?

Any help is appreciated.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2008-05-11 18:43:25 Re: Scripting function definitions as SQL?
Previous Message Postgres User 2008-05-11 18:28:37 Re: Scripting function definitions as SQL?