Importing .csv file into sqlite3 db table

I wrote a single shell script to import a CSV file into a sqlite3 database table.

echo -e '.separator "," \n.import testing.csv aj_test' | sqlite3 ajtest.db

      

sqlite3 database = ajtest.db sqlite3 table in ajtest.db = new_test

test.csv has 3 columns, the first is int, the other two are texts; so accordingly the new_test structure is also -

sqlite> .schema aj_test
CREATE TABLE aj_test(number integer not null,
first_name varchar(20) not null,
last_name varchar(20) not null);

      

when the script is executed it doesn't show any errors, but it also doesn't import any data. Any advice as to what I missed?

content of testing.csv

+3


source to share


2 answers


After much research and discussion, I found the answer that works correctly,

echo -e ".separator ","\n.import /home/aj/ora_exported.csv qt_exported2" | sqlite3 testdatabase.db

      



the main thing was that I needed to specify the path to the CSV file in the import statement.

+4


source


I found this to work:

(echo .separator ,; echo .import path/to/file.csv table_name) | sqlite3 filename.db

      



The accepted answer doesn't work for me.

+1


source







All Articles