Just because I was bored ;) I decided to take a stab at this one as well 
(following Simon's excellent guidance).

I had thought because of what it says in the FAQ here:

http://sqlite.org/faq.html#q1

that it should be possible to import the values directly into the final table 
and have sqlite auto-populate the primary key field as it went.  If it is 
possible, I haven't found any good examples of *how*.

As it is... I came up with the following import-csv.sql file for importing your 
CSV data:

CREATE TABLE t1(ID integer primary key autoincrement, Name varchar(40), 
Category varchar(40), Recommendation varchar(40));
CREATE TABLE t2(a, b, c);
.separator "|"
.import data.csv t2
INSERT INTO t1(Name, Category, Recommendation) SELECT * FROM t2;
DROP TABLE t2;
.headers on
.mode column
.width 5 20 9 15
SELECT * FROM t1;

After that... running the following command should net the resulting output:

E:\sqlite>sqlite3 temp.db ".read import-csv.sql"
ID     Name                  Category   Recommendation
-----  --------------------  ---------  ---------------
1      Barracuda             seafood    No
2      Catfish               seafood    No
3      Caviar                seafood    No
4      Conch                 seafood    No
5      Herring(pickled)      seafood    No
6      Lox(smoked salmon)    seafood    No
7      Octopus               seafood    No

E:\sqlite>



Not sure if that was exactly what the OP was after, but it kept me 
entertained ;)

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to