Thread: How to test a function in pgAdmin?

How to test a function in pgAdmin?

From
"Jacques Koorts"
Date:

Is it possible to test a function in pgAdmin?

 

If so then how do you test a function that returns a cursor? I only get "<unnamed portal 2>" when I run my function.

 

In MSSQL you can test stored procedures that returns a “select * from table”

 

Thanks for any help

jk

Re: How to test a function in pgAdmin?

From
Bob
Date:

Post the code you have an a usuage example makes it alot easier to understand what you are doing.

See manual http://www.postgresql.org/docs/8.1/interactive/plpgsql-cursors.html#PLPGSQL-CURSOR-USING

CREATE TABLE table_1 (c1 varchar(10));
INSERT INTO table_1
SELECT 'some text1';
INSERT INTO table_1
SELECT 'some text2';
select * from table_1

CREATE OR REPLACE FUNCTION myfunc(refcursor) RETURNS SETOF refcursor AS $$
BEGIN
    OPEN $1 FOR SELECT * FROM table_1;
    RETURN NEXT $1;
END;
$$ LANGUAGE plpgsql;

-- need to be in a transaction to use cursors.
BEGIN;
SELECT * FROM myfunc('a');
FETCH ALL FROM a;
COMMIT;
 

On 9/22/06, Jacques Koorts <jacques@vine.co.za> wrote:

Is it possible to test a function in pgAdmin?

 

If so then how do you test a function that returns a cursor? I only get "<unnamed portal 2>" when I run my function.

 

In MSSQL you can test stored procedures that returns a "select * from table"

 

Thanks for any help

jk