HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlCritical

How to properly format sqlite shell output?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
formatproperlysqliteoutputshellhow

Problem

If I go to mysql shell and type SELECT * FROM users I get -

+--------+----------------+---------------------------------+----------+-----------+--------------------+--------------------+
| USERID | NAME           | EMAILID                         | PASSWORD | USER_TYPE | CONTACT_ID_FKUSERS | COMPANY_ID_FKUSERS |
+--------+----------------+---------------------------------+----------+-----------+--------------------+--------------------+
|    137 | X              | b@cc.com                        | #        | ADMIN     |                166 |                110 |
|    138 | Kshitiz        | ksharma@aaa.com                 | asdf     | ADMIN     |                167 |                111 |
+--------+----------------+---------------------------------+----------+-----------+--------------------+--------------------+


Oracle sqlplus shows -

USERID     NAME  EMAILID    PASSWORD   USER_TYPE  CONTACT_ID_FKUSERS COMPANY_ID_FKUSERS
---------- ----- ---------- ---------- ---------- ------------------ ------------------
137        X     b@cc.com   #          ADMIN                     166                110
137        X     b@cc.com   #          ADMIN                     166                110


Sqlite shell shows -

137|X|b@cc.com|#|ADMIN|166|110
138|Kshitiz|ksharma@aaa.com|asdf|ADMIN|167|111


  • Is there a way to beautify the output from sqlite shell?



  • Is there an alternative shell that's better than default distribution? (CLI clients only)

Solution

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

Code Snippets

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

Context

StackExchange Database Administrators Q#40656, answer score: 199

Revisions (0)

No revisions yet.