This is just purely for eye candy while working with SQLite in the terminal, but is there a way to format column width with headers so that each header is resized appropriately (and independently of the other columns)? In other words, here's the output with
.width auto
for a simple table
Id Name Price
---------- ---------- ----------
1 Audi 52642
2 Mercedes 57127
3 Skoda 9000
4 Volvo 29000
5 Bentley 350000
6 Citroen 21000
7 Hummer 41400
8 Volkswagen 21600
It does what I'd expect. It resizes each column so that the longest item in any one column can be displayed. However, I'd like to automatically have the output formatted such that each column is wide enough for the longest item in only its column. In other words, I don't want to have to type in
.width 2 10 5
after the fact to get this output
Id Name Price
-- ---------- -----
1 Audi 52642
2 Mercedes 57127
3 Skoda 9000
4 Volvo 29000
5 Bentley 35000
6 Citroen 21000
7 Hummer 41400
8 Volkswagen 21600
Is there something I can do to automate column sizing correctly?
The sqlite3 program is able to show the results of a query in eight different formats: "csv", "column", "html", "insert", "line", "list", "tabs", and "tcl". You can use the ". mode" dot command to switch between these output formats.
Pretty simple really. Therefore, to enable column headers, simply use . headers on . As mentioned, you can disable column headers using .
Terminate the sqlite3 program by typing your system End-Of-File character (usually a Control-D). Use the interrupt character (usually a Control-C) to stop a long-running SQL statement.
The sqlite3
tool has no such function.
You would have to compute the column widths by hand (SELECT max(length(col1)) ...
).
For "human readable" output, you can use column
mode, and turn header
output on. That will get you something similar to the sqlplus
output in your examples:
sqlite> select * from foo;
234|kshitiz|dba.se
sqlite> .mode column
sqlite> select * from foo;
234 kshitiz dba.se
sqlite> .headers on
sqlite> select * from foo;
bar baz baf
---------- ---------- ----------
234 kshitiz dba.se
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With