Skip to content

Instantly share code, notes, and snippets.

@fgregg
Created February 25, 2020 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fgregg/e839dcc0305909a3bdb3a0a3cc56bd61 to your computer and use it in GitHub Desktop.
Save fgregg/e839dcc0305909a3bdb3a0a3cc56bd61 to your computer and use it in GitHub Desktop.
offset batch
def batched_result_generator(cur):
offset = 0
batchsize = 100
exhausted = False
while not exhausted:
results = cur.execute('select ... from offset = ? limit = ?', (offset, batchsize)).fetchall()
if len(results) < batchsize:
exhausted = True
for row in results:
yield row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment