Created
January 9, 2016 01:50
-
-
Save gwax/8e3504449da9978039ed to your computer and use it in GitHub Desktop.
Simple way to use an interable rather than a list for executing queries across many values.
This file contains 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
import itertools | |
def execute_from_iterable(conn, query, values_iterable, batch_size=1000): | |
values_iterator = iter(values_iterable) | |
while True: | |
batch = list(itertools.islice(values_iterator, batch_size)) | |
if not batch: | |
return | |
conn.execute(query, batch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment