Skip to content

FETCH doesn't work #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sifat144 opened this issue Aug 15, 2023 · 0 comments
Open

FETCH doesn't work #143

sifat144 opened this issue Aug 15, 2023 · 0 comments

Comments

@sifat144
Copy link
Collaborator

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 execute the following inside pgAdmin:

SELECT * FROM get_all();
FETCH ALL IN "<unnamed cursor 1>";
FETCH ALL IN "<unnamed cursor 2>";
it just works. Note - the unnamed cursors are updated on every run.

But when I do exactly the same in node-postgres, I'm getting this -

{ error: cursor "<unnamed portal 1>" does not exist
at Connection.parseE (D:\NodeJS\tests\node_modules\pg\lib\connection.js:546:11)
at Connection.parseMessage (D:\NodeJS\tests\node_modules\pg\lib\connection.js:371:19)
at Socket. (D:\NodeJS\tests\node_modules\pg\lib\connection.js:114:22)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:264:12)
at readableAddChunk (_stream_readable.js:251:11)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onread (net.js:587:20)
name: 'error',
length: 102,
severity: 'ERROR',
code: '34000',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'portalcmds.c',
line: '168',
routine: 'PerformPortalFetch' }
The cursor definitely exists, and I'm executing it against the same connection.

Why doesn't it work?

Do I really need the additional library to fetch the data?

Should it not be simpler, especially in the context of now supporting multiple results? One of the most important examples is to be able to return multiple cursors, i.e. when we now can concatenate several FETCH queries into one, execute it and presumably get all records from all the cursors fetched?

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

No branches or pull requests

1 participant