From 8daea7f1265ddcce67d28258068a25666954000f Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Wed, 6 Nov 2019 20:27:11 -0800 Subject: [PATCH] Handle empty lists --- sqlite_utils/db.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sqlite_utils/db.py b/sqlite_utils/db.py index a51bba7..d44b238 100644 --- a/sqlite_utils/db.py +++ b/sqlite_utils/db.py @@ -977,7 +977,10 @@ class Table(Queryable): # we need to adjust the batch_size down if we have too many cols records = iter(records) # Peek at first record to count its columns: - first_record = next(records) + try: + first_record = next(records) + except StopIteration: + return self # It was an empty list num_columns = len(first_record.keys()) assert ( num_columns <= SQLITE_MAX_VARS