MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

cursor prefetch with bounded lag #1149

Open ale-dd opened 4 months ago

ale-dd commented 4 months ago

EDIT: nvm, looks like there's really no mechanism in the pgwire protocol that would support this behavior.

Would it at all be possible to support prefetching a batch of up to N rows via a cursor, as compared to waiting for exactly N rows to be available?

In other words, I would like to have a max_lag parameter similar to timeout, but with different semantics. If after max_lag at least 1 row, yet less than prefetch rows are available, do return the available rows.

Current api is:

cursor(query, *args, prefetch=None, timeout=None, record_class=None)

I would like it to be augmented as:

cursor(query, *args, prefetch=None, max_lag=None, timeout=None, record_class=None)

Is there any intrinsic limitation that would make this not worth the effort or simply there has been no interest for anything like that?

Thank you!