Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Created January 10, 2021 18:42
Show Gist options
  • Select an option

  • Save narenaryan/194c19debc5f5d909be4dd4cde08efd4 to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/194c19debc5f5d909be4dd4cde08efd4 to your computer and use it in GitHub Desktop.
cursor-illu
CLIENT_PAGINATION_LIMIT = 200
SERVER_PAGINATION_LIMIT = 500
def main():
sql_query = 'SELECT * FROM film'
with connect(**config) as conn:
with conn.cursor("film") as cur:
# This fetches only 100 records from DB as batches
# If you don't specify, the default value is 2000
cur.itersize = SERVER_PAGINATION_LIMIT
cur.execute(sql_query)
while rows := cur.fetchmany(CLIENT_PAGINATION_LIMIT):
if not rows:
break
print(rows) # process the batch here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment