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

Change the Separator to a Comma in SQLite Query Results

By default, the SQLite command line shell formats query output as a pipe-separated list, without column headers.

If you need to output the results using commas instead of the pipe-symbol, you can specify this with the .separator dot command.

If you need to format your results as string literals, see How to Enclose Strings in Single Quotes. Or if you need any strings to be enclosed in double quotes, see How to Format Results as CSV.

Continue reading

Format SQLite Query Results as Columns with Column Headers

By default, when you connect to the SQLite command line shell and run a query, the result is returned as a pipe separated list.

You might have noticed that the results don’t include the column names, which can make your results confusing if you’re trying to read them, especially if the query returned many columns.

Fortunately, there’s an easy way to format the output so that it’s displayed as a column with column headers.

Continue reading