Skip to content

Instantly share code, notes, and snippets.

@ksindi
Created February 21, 2016 19:20
Show Gist options
  • Save ksindi/13cb12e10e65b67f9521 to your computer and use it in GitHub Desktop.
Save ksindi/13cb12e10e65b67f9521 to your computer and use it in GitHub Desktop.
Yields rows in chunks.
def chunk_query(sql, cursor, chunksize=10):
"""Yields rows in chunks."""
cursor.execute(sql)
while True:
nextrows = cursor.fetchmany(chunksize)
if not nextrows:
break
yield nextrows
def iquery(sql, cursor, chunksize=10):
"""Yields row in chunks."""
for row in chunk_query(sql, cursor, chunksize=chunksize):
yield row
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment