1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 23:28:02 +00:00

Add Display Results In Readable Column Format as a SQLite TIL

This commit is contained in:
jbranchaud
2023-12-02 22:16:14 -06:00
parent 6f2ae93e45
commit 851af3776d
2 changed files with 42 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
# Display Results In Readable Column Format
By default the output of a query or pragma command will be pretty squished and
unreadable.
```sql
sqlite> PRAGMA table_info(User);
0|id|TEXT|1||1
1|name|TEXT|0||0
2|email|TEXT|0||0
3|emailVerified|DATETIME|0||0
4|image|TEXT|0||0
```
However, this can be improved by setting the output `mode` to `column`.
```sql
sqlite> .mode column
```
With that set, we can run the same command which will now output nicely
formatted columns with headers.
```sql
sqlite> PRAGMA table_info(User);
cid name type notnull dflt_value pk
--- ------------- -------- ------- ---------- --
0 id TEXT 1 1
1 name TEXT 0 0
2 email TEXT 0 0
3 emailVerified DATETIME 0 0
4 image TEXT 0 0
```
For more details on this and the many other output modes, check out [the
docs](https://sqlite.org/cli.html#changing_output_formats).