Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Reading a cursor from name #34

Open
vitaly-t opened this issue Oct 16, 2017 · 2 comments
Open

Reading a cursor from name #34

vitaly-t opened this issue Oct 16, 2017 · 2 comments

Comments

@vitaly-t
Copy link

vitaly-t commented Oct 16, 2017

Following this issue: brianc/node-postgres#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.

@langpavel
Copy link

Try open transaction explicitly by BEGIN command

@rdb7390
Copy link

rdb7390 commented Oct 26, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants