Display Column Names Alongside Query Results in SQLite3
There’s a simple way to include column headers with your query data, greatly enhancing readability and making your data analysis more efficient.
Before you even execute your query, you just need to set up a couple of SQLite3 commands. Open your SQLite3 command-line interface and type:
.header on
.mode column
What do these commands do?
.header on
: This tells SQLite to include the column names in the output..mode column
: This sets the display mode to ‘column’, allowing for a prettier, table-like format when you view your query results.
However, sometimes you’ll encounter a different issue: your query returns rows that are just too wide, making the output wrap and become difficult to read. In such cases, .mode column
might not be the best choice. Instead, you might find .mode line
more helpful. It arranges the data vertically, with each field on a separate line, shown like this:
<field name> = <field value>
To switch to this mode, simply run:
.mode line
Now, when you execute your query, you’ll get a clear and manageable display, regardless of how wide the data is.