insert_all(..., alter=True) should work for new columns introduced after the first 100 records
See original GitHub issueIs there a way to make .insert_all()
work properly when new columns are introduced outside the first 100 records (with or without the alter=True
argument)?
I’m using .insert_all()
to bulk insert ~3-4k records at a time and it is common for records to need to introduce new columns. However, if new columns are introduced after the first 100 records, sqlite_utils
doesn’t even raise the OperationalError: table ... has no column named ...
exception; it just silently drops the extra data and moves on.
It took me a while to find this little snippet in the documentation for .insert_all()
(it’s not mentioned under Adding columns automatically on insert/update):
The column types used in the CREATE TABLE statement are automatically derived from the types of data in that first batch of rows. Any additional or missing columns in subsequent batches will be ignored.
I tried changing the batch_size
argument to the total number of records, but it seems only to effect the number of rows that are committed at a time, and has no influence on this problem.
Is there a way around this that you would suggest? It seems like it should raise an exception at least.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
Thanks @simonwiles, this is now released in 2.16.1: https://sqlite-utils.readthedocs.io/en/stable/changelog.html
Thanks! And yeah, I had updating the docs on my list too 😃 Will try to get to it this afternoon (budgeting time is fraught with uncertainty at the moment!).