Created
February 21, 2016 19:20
-
-
Save ksindi/13cb12e10e65b67f9521 to your computer and use it in GitHub Desktop.
Yields rows in chunks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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