98 words
1 minute
Copy tables between SQLite databases
Anubhav Gain
2024-05-05

Copy tables between SQLite databases#

I figured out a pattern for doing this today using the sqlite3 CLI tool - given two SQLite databases in the current folder, called tils.db and simonwillisonblog.db:

Terminal window
echo "
attach database 'simonwillisonblog.db' as simonwillisonblog;
attach database 'tils.db' as tils;
drop table if exists simonwillisonblog.til;
create table simonwillisonblog.til as select * from tils.til;
update simonwillisonblog.til set shot = null;
" | sqlite3

I’m using that in this GitHub Actions workflow.

That last update simonwillisonblog.til set shot = null line is because the shot column contains a large BLOB screenshot image which I don’t need in the copied table.

Copy tables between SQLite databases
https://mranv.pages.dev/posts/copy-tables-between-sqlite-databases/
Author
Anubhav Gain
Published at
2024-05-05
License
CC BY-NC-SA 4.0