I have multiple sqlite databases with the same schema, and i want to merge them all together, since i have a unique column and there might be risks of duplicates, i am using insert or ignore, in sqlite it would be easy :
sqlite3 database.db3
sqlite> attach './db1.db3' as s1;
sqlite> attach './db2.db3' as s2;
sqlite> attach './db3.db3' as s3;
sqlite> insert or ignore into table (c1, c2, c3) select c1, c2, c3 from s1.table;
sqlite> insert or ignore into table (c1, c2, c3) select c1, c2, c3 from s2.table;
sqlite> insert or ignore into table (c1, c2, c3) select c1, c2, c3 from s3.table;
sqlite> .exit
I read about dump but i dont want to merge the whole schema, just one table, so i thought about this solution, now till here everything is fine but i need to run all this via a bash, i tried the following but it doesnt :
sqlite3 database.db3 "attach './db1.db3' as s1;"
sqlite3 database.db3 "attach './db2.db3' as s2;"
sqlite3 database.db3 "attach './db3.db3' as s3;"
sqlite3 database.db3 "select count(*) from s1.table;"
sqlite3 database.db3 "select count(*) from s2.table;"
sqlite3 database.db3 "select count(*) from s3.table;"
it says Error: no such table: s1.table
What am i doing wrong