.import
不支持重塑输入(设置分隔符除外)。您需要将 CSV 文件导入到临时表中,然后将其插入到真实表中。这是一个示例会话:
$ cat a.csv
1,2
3,4
5,6
$ sqlite3 a.db
SQLite version 3.6.23.1
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table foo(id integer primary key,x,y);
sqlite> create temp table footmp(x,y);
sqlite> .separator ,
sqlite> .import a.csv footmp
sqlite> select * from footmp;
1,2
3,4
5,6
sqlite> insert into foo(x,y) select * from footmp;
sqlite> select * from foo;
1,1,2
2,3,4
3,5,6
sqlite> drop table footmp;
您会看到 ID 已计数。这是因为类型为 INTEGER PRIMARY KEY 的列被视为内部 ROWID 的别名 - 它始终是唯一的升序数字。