You could import into a temporary table with a dummy column:
CREATE TEMP TABLE DummyTable(id, emp, dep, nothing);
.import importfile DummyTable
INSERT INTO MyTable SELECT id, emp, dep FROM DummyTable;
DROP TABLE DummyTable;
문제
I want to load a table with a text file delimited by pipes
Table
--------------------------
Id + Employee + Department
--------------------------
File
0|Some Name|Some department|
1|Another Name|Another department|
I use the .separator command to set the "|" separator and then execute the .import command.
I receive the following error Error: EMP.TXT line 1: expected 3 columns of data but found 4.
I want to know if ther is some option in sqlite3 to ignore the trailing pipe.
해결책
You could import into a temporary table with a dummy column:
CREATE TEMP TABLE DummyTable(id, emp, dep, nothing);
.import importfile DummyTable
INSERT INTO MyTable SELECT id, emp, dep FROM DummyTable;
DROP TABLE DummyTable;
다른 팁
You could remove the superfluous pipe before importing:
< importfile sed 's/|$//' | sqlite3 my.db ".import /dev/stdin MyTable"