Automatically Open SQLite Query Results in Excel

The SQLite command line interface has a handy little feature where you can open your SQL query results in an Excel file.

When you run a query, instead of the query being output to your console as it normally would, it instead opens as an Excel spreadsheet (or LibreOffice, or whatever program your system uses to open CSV files).

You have two options when doing this:

  • Use a temporary file
  • Use a permanent file (i.e. save it for later)

This article covers both options.

Continue reading

Format SQLite Query Results as a Comma-Separated List

SQLite has several modes and settings that enable you to output query results as a comma-separated list.

For example, you can use the .separator dot command to specify a comma as the separator. Or you could use the “quote” mode to format the output as string literals.

However, for the purposes of this article, I’m going to use csv mode, which formats the results as a comma-separated list, as well as with double quotes around strings. Internal double quotes are double-quoted.

Continue reading

Enclose Strings in Single Quotes in SQLite Query Results

When working with the SQLite command line shell, you have the option of having your query results formatted as string literals.

You can do this by switching to “quote” mode. When you do this, strings are enclosed in single-quotes and internal single-quotes are escaped by doubling. Also, blobs are displayed in hexadecimal blob literal notation, numbers are displayed as ASCII text, and NULL values are shown as “NULL”.

If you need to format your results with double quotes, consider using csv mode.

Continue reading