A number of times I’ve needed to export a specific table from an SQLite database to a CSV file.

The sqlite program itself gives a very clean interface for this.

sqlite3 -header -csv database.sqlite "SELECT * FROM artists;" > ./artists.csv

Conversely, if I need do this from the SQLite prompt, I need to do it slightly differently.

I first get into the SQLite prompt with the respective database.

sqlite3 database.sqlite

> .header on
> .mode csv
> .once ./artists.csv

> SELECT * FROM artists;

Which can be further shortened to

sqlite3 -header -csv database.sqlite

> .once ./artists.csv

> SELECT * FROM artists;