sqlsqlitecsvimport

sqlite error importing csv through command line


$ sqlite3 test.sql
SQLite version 3.6.12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table test (id integer, author_id integer, title varchar(128), name text);
sqlite> .separator ";"
sqlite> .import sqlite.csv test
sqlite.csv line 3: expected 4 columns of data but found 1
sqlite> .separator ';'
sqlite> .import sqlite.csv test
sqlite.csv line 3: expected 4 columns of data but found 1
sqlite> 

I am trying to import the csv table with ; as a seperator to sqlite but it wasn't able to find 4 columns. I export from sql to csv with checked 'Put fields names in the first row'. Could I be missing something here?

first 5 lines of csv

id;"author_id";"title";"poem"       
1;"92";"A Letter From Italy";"Salve magna parens frugum Saturnia tellus     
Magna virm! tibi res antiqu laudis et artis     
Aggredior    sanctos ausus recludere fontes.    
Virg. Geor. 2.  

Solution

  • You can't import into a table with a primary key you have to import into a temp table first.

    See the answer to this SO question