Skip to content

Instantly share code, notes, and snippets.

@gwax
Created January 9, 2016 01:50
Show Gist options
  • Save gwax/8e3504449da9978039ed to your computer and use it in GitHub Desktop.
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.
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