Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dump only part of sqlite database

Tags:

sqlite

Is it possible to dump only part of a database? I have a database containing 250'000 entries. I want to create a second one with a tenth of the data in it...

using

select * from table where id % 10 = 0

and setting

.output out.sql

yields a file that does not have the binary data encoded in the same way as when using

.dump

dump -> the binary data gets encoded as hex bytes
other way -> it gets encoded as some weird string
like image 907
kungfoo Avatar asked Nov 15 '25 20:11

kungfoo


1 Answers

Instead of dumping to a file, you can directly write a new database:

ATTACH DATABASE New.db AS new;
CREATE TABLE new.stuff AS (SELECT * FROM table WHERE id % 10 = 0);

This should create the table stuff in New.db.

like image 133
Stephen Jennings Avatar answered Nov 18 '25 13:11

Stephen Jennings