SQLite3 终端输出格式 .width

标签 sql sqlite terminal formatting

这纯粹是为了在终端中使用 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/

相关文章:

java - 如何在终端中杀死这个 tomcat 进程?

mysql - SQL 从逗号分隔的字符串中选择查询

sql - 数据库结构反馈

php - 将 SQLite/Android 数据库表同步到远程 MySQL 数据库表(通过 PHP)

android - 如何在android中显示数据库中的所有行

C 程序。排序算法在命令提示符/终端中不起作用

python - 更新到 Python 3.8 - 终端无法打开 - [已修复] 但细节不明白

mysql - mysql根据周+dayofweek查找日期

sql - 想要使用 mysql 根据表中的状态来选择记录

django - 如何从 Excel 文件填充 django Manytomany 数据库