如何更改 select 输出的格式(SQLite)

How to change the format of select output (SQLite)

SQLite 上,我显示 table“用户”,如下所示,但 select 输出 格式不正确所以很难看:

sqlite> .header on
sqlite> select * from user;
id|first_name|last_name|age
1|Steve|Jobs|56
2|Bill|Gates|66
3|Mark|Zuckerberg|38

我想要格式更好的select输出,如下所示或select任何格式的输出 只要格式比上面的好就可以了:

id|first_name|last_name |age
1 |Steve     |Jobs      |56
2 |Bill      |Gates     |66
3 |Mark      |Zuckerberg|38

是否有任何方法可以更改select输出的格式?

下面这条命令设置输出模式“box”:

.mode box

那么,就是下面这个样子:

sqlite> .header on
sqlite> select * from user;
┌────┬────────────┬────────────┬─────┐
│ id │ first_name │ last_name  │ age │
├────┼────────────┼────────────┼─────┤
│ 1  │ Steve      │ Jobs       │ 56  │
│ 2  │ Bill       │ Gates      │ 66  │
│ 3  │ Mark       │ Zuckerberg │ 38  │
└────┴────────────┴────────────┴─────┘

并且,下面的命令设置输出模式“table”:

.mode table

那么,就是下面这个样子:

sqlite> .header on
sqlite> select * from user;
+----+------------+------------+-----+
| id | first_name | last_name  | age |
+----+------------+------------+-----+
| 1  | Steve      | Jobs       | 56  |
| 2  | Bill       | Gates      | 66  |
| 3  | Mark       | Zuckerberg | 38  |
+----+------------+------------+-----+

共有14种输出模式如下图:

box         Tables using unicode box-drawing characters
csv         Comma-separated values
column      Output in columns.  (See .width)
html        HTML <table> code
insert      SQL insert statements for TABLE
json        Results in a JSON array
line        One value per line
list        Values delimited by "|"
markdown    Markdown table format
qbox        Shorthand for "box --width 60 --quote"
quote       Escape answers as for SQL
table       ASCII-art table
tabs        Tab-separated values
tcl         TCL list elements

并且这些命令显示命令“.mode”的详细信息:

.help .mode

或者:

.help mode

那么,就是下面这个样子:

sqlite> .help .mode
.import FILE TABLE       Import data from FILE into TABLE
   Options:
     --ascii               Use 7 and 6 as column and row separators
     --csv                 Use , and \n as column and row separators
     --skip N              Skip the first N rows of input
     --schema S            Target table to be S.TABLE
     -v                    "Verbose" - increase auxiliary output
   Notes:
     *  If TABLE does not exist, it is created.  The first row of input
        determines the column names.
     *  If neither --csv or --ascii are used, the input mode is derived
        from the ".mode" output mode
     *  If FILE begins with "|" then it is a command that generates the
        input text.
.mode MODE ?OPTIONS?     Set output mode
   MODE is one of:
     ascii       Columns/rows delimited by 0x1F and 0x1E
     box         Tables using unicode box-drawing characters
     csv         Comma-separated values
     column      Output in columns.  (See .width)
     html        HTML <table> code
     insert      SQL insert statements for TABLE
     json        Results in a JSON array
     line        One value per line
     list        Values delimited by "|"
     markdown    Markdown table format
     qbox        Shorthand for "box --width 60 --quote"
     quote       Escape answers as for SQL
     table       ASCII-art table
     tabs        Tab-separated values
     tcl         TCL list elements
   OPTIONS: (for columnar modes or insert mode):
     --wrap N       Wrap output lines to no longer than N characters
     --wordwrap B   Wrap or not at word boundaries per B (on/off)
     --ww           Shorthand for "--wordwrap 1"
     --quote        Quote output text as SQL literals
     --noquote      Do not quote output text
     TABLE          The name of SQL table used for "insert" mode