Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure sqlite to display headers by default

Is there any way to configure sqlite3 so that the headers will display by default?

I know I can use .headers on to turn on headers, but I have to keep typing it every time I launch the client because the setting doesn't stick between sessions. I want the headers to be on permanently.

like image 283
spemmo Avatar asked May 07 '11 21:05

spemmo


People also ask

How do I turn on headers in SQLite?

Pretty simple really. Therefore, to enable column headers, simply use . headers on . As mentioned, you can disable column headers using .

How do I display table contents in SQLite?

To display the structure of a table, you use the . schema TABLE command. The TABLE argument could be a pattern.

Which command is used to view records on column format in SQLite?

The sqlite3 program is able to show the results of a query in eight different formats: "csv", "column", "html", "insert", "line", "list", "tabs", and "tcl". You can use the ". mode" dot command to switch between these output formats. The default output mode is "list".


2 Answers

From the fine manual:

INIT FILE
sqlite3 reads an initialization file to set the configuration of the interactive environment. [...] If the file ~/.sqliterc exists, it is processed first. can be found in the user's home directory, it is read and processed. It should generally only contain meta-commands.

So just put a file called .sqliterc in your home directory and put this in it:

.headers ON 
like image 86
mu is too short Avatar answered Oct 09 '22 06:10

mu is too short


You can pass arguments in the command line too:

sqlite3 db.db  -header -column  "select x from y;" 
like image 24
MaikoID Avatar answered Oct 09 '22 06:10

MaikoID