-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
FETCH doesn't work #1476
Comments
As an update, I did try to use node-pg-cursor, but without success. I'm not even sure it supports reading cursors from their names, so I opened an issues there also: brianc/node-pg-cursor#34 |
Did you try open transaction explicitly by |
@vitaly-t did you make this one work ? |
@SunilManthenaG01 I can't remember what I did or didn't make work 4 years ago 😄 |
Hi. I had the same issue. |
@vitaly-t Did you try using a transaction? I've been successfully using FETCH with pg-promise, something like this: db.tx(async (transaction) => {
await transaction.any("DECLARE my_cursor CURSOR FOR SELECT * FROM table");
let rows = [];
do {
rows = await transaction.manyOrNone("FETCH 100 FROM my_cursor");
// do something with the batch
} while (rows.length > 0);
}); Also according to PostgreSQL docs it should be possible to create cursors outside transactions if you use With this working, do you think there's any performance or other reason to use pg-cursor? |
@sampok It's a 5-year old issue, I cannot recall anything about it at this point. But if it works for you, great, maybe will help somebody else ;) |
This is kind of reviving the old and forgotten #1137, but with new specifics.
I have two tables:
users
+products
, and I have a function that returns two cursors for those:When I execute the following inside
pgAdmin
: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 -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?The text was updated successfully, but these errors were encountered: