这纯粹是为了在终端中使用 SQLite 时吸引眼球,但是有没有办法用标题格式化列宽,以便每个标题都适本地调整大小(并且独立于其他列)?换句话说,这是输出
.width auto
对于一个简单的表格
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
它符合我的预期。它调整每一列的大小,以便可以显示任何一列中最长的项目。但是,我想自动对输出进行格式化,使每列的宽度足以容纳 仅其 列中最长的项目。换句话说,我不想输入
.width 2 10 5
事后得到这个输出
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
我可以做些什么来正确地自动调整列大小吗?
最佳答案
来自 SQLite 的文档:
If you specify a column a width of 0, then the column width is automatically adjusted to be the maximum of three numbers: 10, the width of the header, and the width of the first row of data. This makes the column width self-adjusting. The default width setting for every column is this auto-adjusting 0 value.
关于SQLite3 终端输出格式 .width,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18902428/