Forrest logo
back to the sqlite3 tool

sql:warp:25557

Export SQLite query to a CSV file
$ sqlite3 -header -csv ${db_filepath} ${sql_query} > ${output_filepath}
try on your machine

The given command is used to execute an SQL query on an SQLite database and save the results in CSV format.

Here's the breakdown of the command:

  • sqlite3: It is the command-line interface tool for interacting with SQLite databases.
  • -header: This option is used to include column headers in the output of the query result.
  • -csv: This option tells SQLite to format the query result in CSV (Comma-Separated Values) format.
  • ${db_filepath}: It is the placeholder for the path of the SQLite database file you want to query.
  • ${sql_query}: It is the placeholder for the SQL query you want to execute on the database.
  • >: The output redirection symbol. It redirects the output of the command to a file instead of displaying it on the console.
  • ${output_filepath}: It is the placeholder for the path of the file where you want to save the query result.

To use this command, you need to replace ${db_filepath} with the actual path of your SQLite database file, ${sql_query} with the SQL query you want to execute, and ${output_filepath} with where you want to store the query result in CSV format.

Once you execute the command, the query will be run on the specified SQLite database, and the result, including column headers, will be saved in the specified file in CSV format.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the sqlite3 tool