Output SQLite Query Results as a Tab-Separated List

The SQLite command line interface allows you to use various modes for formatting the result set of SQL queries. For example, you can format the results in columns, as a comma separated list, using vertical output, and more.

This article explains how to use the .mode dot command to format your results as a tab-separated list.

Example

To specify a tab-separated list, use .mode tabs. Then you can run your query as you normally would.

.mode tabs
SELECT * FROM Products;

Result:

1	Widget Holder	139.5
2	Widget Opener	89.7
3	Bob's "Best" Widget	374.2
4	Blue Widget	63.0

Add Column Headers

You can also use .headers on to have the column names appear at the top of each column.

.mode tabs
.headers on
SELECT * FROM Products;

Result:

ProductId	ProductName	Price
1	Widget Holder	139.5
2	Widget Opener	89.7
3	Bob's "Best" Widget	374.2
4	Blue Widget	63.0

The result can sometimes resemble using .mode column, but this depends on the data being returned.

If you want your results returned in columns, you’re better off specifying columns.

Save the Settings

You can save these settings in a configuration file so that you don’t have to re-enter them each time you open the SQLite CLI.

To do this, add the following to a text file:

.mode tabs
.headers on

Then save that file as .sqliterc in your home folder. Each time you use the SQLite command line interface, it will check that configuration file for your personal settings.