Created
January 10, 2021 18:42
-
-
Save narenaryan/194c19debc5f5d909be4dd4cde08efd4 to your computer and use it in GitHub Desktop.
cursor-illu
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
| 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