I saw in the docs that you need to use server-side ("named") cursors to avoid loading all results into memory at once. But then I found that server-side cursors aren't reusable. You can only do a single .execute
on them. (Otherwise you get ProgrammingError: can't call .execute() on named cursors more than once
.)
Is there any way to get a cursor that I can re-use, but that also will not load all the data into memory at once?
I'm open to using a different Postgres driver if it will make things easier and more performant. I looked at PyGreSQL but it seems noticeably slower than a Postgres named cursor.