Search code examples
csvimportsqlitespatialite

SQLITE: import data from a CSV


I need to import in a SQLITE database a CSV file that use both numbers than strings: here you a sample ..

col_1|col_2|col_3
10|text2|http://www.google.com

For the import I use Spatialite GUI because I've to manage also spatial data: all works fine in the import but when I try to select the data

select * from test;

enter image description here

How I've to structure my CSV file to store my "text2" string?


Solution

  • I've solved in a different manner ....

    Enter in Sqlite and give these commands:

    CREATE TABLE ps_details(
      col_1 TEXT,
      col_2 TEXT,
      col_3 TEXT
    );
    .mode csv
    .separator |
    .import test.csv test
    .quit
    

    You can save this in a file (es. test.txt) and then, in a second file named test.sh write

    sqlite3 dbtest.sqlite < test.txt
    

    save and change its permission (chmod 777), and then launch it form comand line

    ./test.sh
    

    This will create a table test in your dbtest.sqlite getting data form test.csv file