Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.  
like image 938
merrill Avatar asked Feb 03 '23 09:02

merrill


1 Answers

Since your separator is only a single character, try using the separator command without quotes around the semicolon. So:

sqlite> .separator ;
sqlite> .import sqlite.csv test
like image 175
Mike Monteiro Avatar answered Feb 05 '23 05:02

Mike Monteiro