node-pg-cursor icon indicating copy to clipboard operation
node-pg-cursor copied to clipboard

Reading a cursor from name

Open vitaly-t opened this issue 7 years ago • 2 comments

Following this issue: https://github.com/brianc/node-postgres/issues/1476


I have two tables: users + products, and I have a function that returns two cursors for those:

CREATE or replace FUNCTION get_all() RETURNS SETOF refcursor AS
$BODY$
DECLARE
    u refcursor;
    p refcursor;
BEGIN
    OPEN u FOR
    SELECT * FROM users;
    RETURN NEXT u;

    OPEN p FOR
    SELECT * FROM products;
    RETURN NEXT p;
END
$BODY$ LANGUAGE plpgsql;

When I query SELECT * FROM get_all(), I am getting the following data back:

[ anonymous { get_all: '<unnamed portal 1>' },
  anonymous { get_all: '<unnamed portal 2>' } ]

How can I initiate a cursor read from the cursor names, using this library?


Please note that when I am executing the following in pgAdmin:

SELECT * FROM get_all();
FETCH ALL IN "<unnamed cursor 1>";
FETCH ALL IN "<unnamed cursor 2>";

I am getting all the data correctly for the 2 tables.

vitaly-t avatar Oct 16 '17 02:10 vitaly-t

Try open transaction explicitly by BEGIN command

langpavel avatar Nov 14 '17 03:11 langpavel

How to read data from cursor name ? result received - anonymous { Function Name: '<unnamed portal 1>' }

rdb7390 avatar Oct 26 '18 10:10 rdb7390