SQLite Forum

csv import without header row
Login

csv import without header row

(1) By anonymous on 2020-06-10 01:07:32 [link] [source]

From the cli page, it mentions that you can skip the header row by using the option --skip 1. However, I have not been able to make it work. Can you give an example or syntax of using that option?

(2) By Larry Brasfield (LarryBrasfield) on 2020-06-10 01:31:32 in reply to 1 [link] [source]

Study this session scrape:

sqlite> create table Pets (name text, species text);
sqlite> insert into Pets values('Fido', 'dog');
sqlite> insert into Pets values('Fluffy', 'cat');
sqlite> insert into Pets values('Hiss', 'serpent');
sqlite> .mode csv
sqlite> .header on
sqlite> .once pets.csv
sqlite> select * from Pets;
sqlite> create table Beasts (name text, species text);
sqlite> .import --csv --skip 1 pets.csv Beasts
sqlite> select * from Beasts;
name,species
Fido,dog
Fluffy,cat
Hiss,serpent
sqlite>

(4) By L Carl (lcarlp) on 2020-06-13 14:09:23 in reply to 2 [link] [source]

Unrelated to the original question:

I guess the “--csv” option is something new? Maybe it overrides the current mode? Where is that documented?

(5) By Warren Young (wyoung) on 2020-06-13 14:58:24 in reply to 4 [link] [source]

Here.

(6.1) By Larry Brasfield (LarryBrasfield) on 2020-06-13 18:16:01 edited from 6.0 in reply to 4 [source]

It should be documented in the CLI Shell docs, but is not. Because ".mode csv" had already been entered in the session I showed, that option was not necessary. But if you had not set the CSV mode before the import, that --csv option makes it happen during the import.

You can see its effect mentioned in the CLI shell by entering:

.help import

or

.help -all

, (and scrolling back for the latter unless you have a huge monitor and a tiny font.)

(3) By Simon Slavin (slavin) on 2020-06-10 17:37:29 in reply to 1 [link] [source]

To import a file without headers you must have your table already created. Is that what you tried ? If so, describe what's going wrong.