Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the SQLite CLI's "--skip 1" option?

Tags:

sqlite

csv

I'm importing several CSV files into a single table. The documentation for CSV import says

when the table already exists, every row of the CSV file, including the first row, is assumed to be actual content. If the CSV file contains an initial row of column labels, you can cause the .import command to skip that initial row using the "--skip 1" option.

But I can't seem to figure out a valid way to pass that flag. I tried the following:

sqlite> .import foo.csv contributions --skip 1
Usage: .import FILE TABLE

sqlite> .import --skip 1 foo.csv contributions
Usage: .import FILE TABLE

sqlite> .import foo.csv --skip 1 contributions
Usage: .import FILE TABLE

I'm using version 3.30.1.

like image 301
user2752467 Avatar asked May 24 '20 04:05

user2752467


People also ask

How do I import a CSV file into SQLite?

First, from the menu choose tool menu item. Second, choose the database and table that you want to import data then click the Next button. Third, choose CSV as the data source type, choose the CSV file in the Input file field, and choose the ,(comma) option as the Field separator as shown in the picture below.

Which of the following command is used to open a CSV file automatically?

system command is used to automatically open the CSV file.

Which of the following command is used to export data to CSV SQLite?

In SQLite, by using “. output” command we can export data from database tables to CSV or excel external files based on our requirement.


Video Answer


1 Answers

I find that on 3.32.0, this will work to skip the first two rows, the header row and the first data row:

.import --csv --skip 2 file.csv tablename

The issue may be where you say:

I'm using 3.30.1

According to the sqlite release notes, the --skip option was implemented in 3.32.0:

SQLite Release 3.32.0 On 2020-05-29 ... 9. Enhancements to the CLI: (a) Add options to the .import command: --csv, --ascii, --skip

You can get the newest versions from the official download page.

like image 55
Paul Avatar answered Nov 15 '22 09:11

Paul