Cesare
Cesare

Reputation: 1749

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?

Upvotes: 2

Views: 1112

Answers (2)

Cesare
Cesare

Reputation: 1749

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

Upvotes: 1

zwippie
zwippie

Reputation: 15515

It looks like you defined the type of col_2 as REAL, where it should be TEXT.

The structure of your CSV look ok.

Disclaimer: I have never used Spatialite, this is just from looking at the information you provided.

Upvotes: 0

Related Questions