Skip to content
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

Explain iterable cursors in the documentation #677

Open
wrobell opened this issue Dec 16, 2020 · 1 comment
Open

Explain iterable cursors in the documentation #677

wrobell opened this issue Dec 16, 2020 · 1 comment

Comments

@wrobell
Copy link

wrobell commented Dec 16, 2020

When running

await conn.cursor(sql, prefetch=100)

I am getting error

asyncpg.exceptions._base.InterfaceError: prefetch argument can only be specified for iterable cursor

Looking into the documentation, I cannot find anything about iterable cursors. How do I declare them?

@elprans
Copy link
Member

elprans commented Mar 8, 2021

Here's the relevant part of the documentation: https://magicstack.github.io/asyncpg/current/api/index.html#cursors.

Iterable cursors are cursors that are used directly as iterator rather than an object that calling fetch(), so

# cursor with manual control
# prefetch doesn't make sense, because
# you specify the number of rows fetched explicitly
# every time
cursor = await conn.cursor(sql)
rows = await cursor.fetch(100)
# iterable cursor
# runs "fetch(100)" behind the scenes on every
# 100th iteration.
async for record in conn.cursor(sql, prefetch=100):
   ...

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

2 participants