question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

insert_all(..., alter=True) should work for new columns introduced after the first 100 records

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
simonwcommented, Aug 28, 2020
0reactions
simonwilescommented, Aug 28, 2020

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!).

Read more comments on GitHub >

github_iconTop Results From Across the Web

4. Inserting, Updating, Deleting - SQL Cookbook [Book] - O'Reilly
The INSERT statement allows you to create new rows in database tables. ... In this recipe's example, INSERT ALL and INSERT FIRST would...
Read more >
SQL: Insert all records from one table to another table without ...
Is it possible to do bulk insert from one table to another without supply the column name? I've google it but can't seem...
Read more >
INSERT INTO SELECT statement overview and examples
We want to insert all records from the Employees table to the Customers ... Add a new column in Employees table using ALTER...
Read more >
Tutorial: Adding and Saving Rows: Databases for Developers
This tutorial shows you how insert works using these two tables: ... Any table columns you don't provide a value for will store...
Read more >
Insert or delete rows and columns - Microsoft Support
When you select a row or column that has formatting applied, that formatting will be transferred to a new row or column that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found