node-pg-cursor
node-pg-cursor copied to clipboard
Reading a cursor from name
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.
Try open transaction explicitly by BEGIN
command
How to read data from cursor name ? result received - anonymous { Function Name: '<unnamed portal 1>' }