Is the output of sqlite in "mode .insert" correct?

1.4k Views Asked by At

Consider the table I create in SQLite database with CREATE TABLE tbl(x); which has the following data: INSERT INTO tbl VALUES(1); INSERT INTO tbl VALUES(2);. Now I wish to create a SQL file of this schema and data that I wish to import into PostgreSQL and I do the following:

.mode insert
.output "tbl.sql"
.schema tbl
select * from tbl order by x;
.output stdout

And the output is:

CREATE TABLE tbl(x);
INSERT INTO table VALUES(1);
INSERT INTO table VALUES(2);

Shouldn't the output of the insert statements be INSERT INTO tbl VALUES(1); INSERT INTO tbl VALUES(2); ?

This is not really a problem because I can easily do a find/repalce to fix this but that might potentially introduce unforeseen problems (like changing data inside the insert statement).

1

There are 1 best solutions below

1
On BEST ANSWER

From the fine SQLite manual:

When specifying insert mode, you have to give an extra argument which is the name of the table to be inserted into. For example:

sqlite> .mode insert new_table
sqlite> select * from tbl1;
INSERT INTO "new_table" VALUES('hello',10);
INSERT INTO "new_table" VALUES('goodbye',20);
sqlite>

So saying .mode insert leaves SQLite to use the default table name which is apparently table. You should be saying:

.mode insert tbl