The .headers
command is crucial as might effect the way the result set is displayed. The first row would be set to the name of the columns in the output of the relevant commands like .output
, .once
, or even your simple standard out queries if it is set on.
.headers on
OR
.header on
Some how either of them work. You need to set it to on
to enable the headers in the output of the result set. And you can turn off with .headers off
.
Which modes are effected with this command if set on or off?
Well we need to think about how effected means
- Only added in the first row
- Added in each row
- No effect
- Only added in the first row
- ascii
- column
- csv
- html
- list
- quote
- tabs
- tcl
- Added in each row
- insert
- No effect
- box
- json
- line
- markdown
- table
Reference table
CREATE TABLE IF NOT EXISTS books(
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
author TEXT NOT NULL,
pages INTEGER NOT NULL,
release_date TEXT NOT NULL,
price REAL NOT NULL
);
INSERT INTO books(title, author, pages, release_date, price)
VALUES
('The Hobbit', 'J.R.R. Tolkien', 310, '1937-09-21', 39.99),
('The Fellowship of the Ring', 'J.R.R. Tolkien', 423, '1954-07-29', 49.99),
('The Two Towers', 'J.R.R. Tolkien', 352, '1954-11-11', 49.99),
('The Return of the King', 'J.R.R. Tolkien', 416, '1955-10-20', 49.99);
SELECT * FROM books;
Below are the outputs of each command
Added on the first row
In the below modes, the headers command if set will add the column name as the header in the first row.
- ASCII
.mode ascii
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode ascii
sqlite> .headers on
sqlite> select * from books;
idtitleauthorpagesrelease_dateprice1The HobbitJ.R.R. Tolkien3101937-09-2139.992The Fellowship of the RingJ.R.R. Tolkien4231954-07-2949.993The Two TowersJ.R.R. Tolkien3521954-11-1149.994The Return of the KingJ.R.R. Tolkien4161955-10-2049.99sqlite>
sqlite> .headers off
sqlite> select * from books;
1The HobbitJ.R.R. Tolkien3101937-09-2139.992The Fellowship of the RingJ.R.R. Tolkien4231954-07-2949.993The Two TowersJ.R.R. Tolkien3521954-11-1149.994The Return of the KingJ.R.R. Tolkien4161955-10-2049.99sqlite>
sqlite>
- Column
.mode column
.headers on
select * from books;
.headers off
select * from books;
Output
sqlite> .mode column
sqlite> .headers on
sqlite> select * from books;
id title author pages release_date price
-- -------------------------- -------------- ----- ------------ -----
1 The Hobbit J.R.R. Tolkien 310 1937-09-21 39.99
2 The Fellowship of the Ring J.R.R. Tolkien 423 1954-07-29 49.99
3 The Two Towers J.R.R. Tolkien 352 1954-11-11 49.99
4 The Return of the King J.R.R. Tolkien 416 1955-10-20 49.99
sqlite> .headers off
sqlite> select * from books;
1 The Hobbit J.R.R. Tolkien 310 1937-09-21 39.99
2 The Fellowship of the Ring J.R.R. Tolkien 423 1954-07-29 49.99
3 The Two Towers J.R.R. Tolkien 352 1954-11-11 49.99
4 The Return of the King J.R.R. Tolkien 416 1955-10-20 49.99
sqlite>
- CSV
.mode csv
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode csv
sqlite> .headers on
sqlite> select * from books;
id,title,author,pages,release_date,price
1,"The Hobbit","J.R.R. Tolkien",310,1937-09-21,39.99
2,"The Fellowship of the Ring","J.R.R. Tolkien",423,1954-07-29,49.99
3,"The Two Towers","J.R.R. Tolkien",352,1954-11-11,49.99
4,"The Return of the King","J.R.R. Tolkien",416,1955-10-20,49.99
sqlite> .headers off
sqlite> select * from books;
1,"The Hobbit","J.R.R. Tolkien",310,1937-09-21,39.99
2,"The Fellowship of the Ring","J.R.R. Tolkien",423,1954-07-29,49.99
3,"The Two Towers","J.R.R. Tolkien",352,1954-11-11,49.99
4,"The Return of the King","J.R.R. Tolkien",416,1955-10-20,49.99
sqlite>
- HTML
.mode html
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode html
sqlite> .headers on
sqlite> select * from books;
id
title
author
pages
release_date
price
1
The Hobbit
J.R.R. Tolkien
310
1937-09-21
39.99
2
The Fellowship of the Ring
J.R.R. Tolkien
423
1954-07-29
49.99
3
The Two Towers
J.R.R. Tolkien
352
1954-11-11
49.99
4
The Return of the King
J.R.R. Tolkien
416
1955-10-20
49.99
sqlite> .headers off
sqlite> select * from books;
1
The Hobbit
J.R.R. Tolkien
310
1937-09-21
39.99
2
The Fellowship of the Ring
J.R.R. Tolkien
423
1954-07-29
49.99
3
The Two Towers
J.R.R. Tolkien
352
1954-11-11
49.99
4
The Return of the King
J.R.R. Tolkien
416
1955-10-20
49.99
sqlite>
- List
.mode list
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode list
sqlite> .headers on
sqlite> select * from books;
id|title|author|pages|release_date|price
1|The Hobbit|J.R.R. Tolkien|310|1937-09-21|39.99
2|The Fellowship of the Ring|J.R.R. Tolkien|423|1954-07-29|49.99
3|The Two Towers|J.R.R. Tolkien|352|1954-11-11|49.99
4|The Return of the King|J.R.R. Tolkien|416|1955-10-20|49.99
sqlite> .headers off
sqlite> select * from books;
1|The Hobbit|J.R.R. Tolkien|310|1937-09-21|39.99
2|The Fellowship of the Ring|J.R.R. Tolkien|423|1954-07-29|49.99
3|The Two Towers|J.R.R. Tolkien|352|1954-11-11|49.99
4|The Return of the King|J.R.R. Tolkien|416|1955-10-20|49.99
sqlite>
- Quote
.mode quote
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode quote
sqlite> .headers on
sqlite> select * from books;
'id','title','author','pages','release_date','price'
1,'The Hobbit','J.R.R. Tolkien',310,'1937-09-21',39.99000000000000198
2,'The Fellowship of the Ring','J.R.R. Tolkien',423,'1954-07-29',49.99000000000000198
3,'The Two Towers','J.R.R. Tolkien',352,'1954-11-11',49.99000000000000198
4,'The Return of the King','J.R.R. Tolkien',416,'1955-10-20',49.99000000000000198
sqlite> .headers off
sqlite> select * from books;
1,'The Hobbit','J.R.R. Tolkien',310,'1937-09-21',39.99000000000000198
2,'The Fellowship of the Ring','J.R.R. Tolkien',423,'1954-07-29',49.99000000000000198
3,'The Two Towers','J.R.R. Tolkien',352,'1954-11-11',49.99000000000000198
4,'The Return of the King','J.R.R. Tolkien',416,'1955-10-20',49.99000000000000198
sqlite>
- Tabs
.mode tabs
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode tabs
sqlite> .headers on
sqlite> select * from books;
id title author pages release_date price
1 The Hobbit J.R.R. Tolkien 310 1937-09-21 39.99
2 The Fellowship of the Ring J.R.R. Tolkien 423 1954-07-29 49.99
3 The Two Towers J.R.R. Tolkien 352 1954-11-11 49.99
4 The Return of the King J.R.R. Tolkien 416 1955-10-20 49.99
sqlite> .headers off
sqlite> select * from books;
1 The Hobbit J.R.R. Tolkien 310 1937-09-21 39.99
2 The Fellowship of the Ring J.R.R. Tolkien 423 1954-07-29 49.99
3 The Two Towers J.R.R. Tolkien 352 1954-11-11 49.99
4 The Return of the King J.R.R. Tolkien 416 1955-10-20 49.99
sqlite>
- TCL
.mode tcl
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode tcl
sqlite> .headers on
sqlite> select * from books;
"id" "title" "author" "pages" "release_date" "price"
"1" "The Hobbit" "J.R.R. Tolkien" "310" "1937-09-21" "39.99"
"2" "The Fellowship of the Ring" "J.R.R. Tolkien" "423" "1954-07-29" "49.99"
"3" "The Two Towers" "J.R.R. Tolkien" "352" "1954-11-11" "49.99"
"4" "The Return of the King" "J.R.R. Tolkien" "416" "1955-10-20" "49.99"
sqlite> .headers off
sqlite> select * from books;
"1" "The Hobbit" "J.R.R. Tolkien" "310" "1937-09-21" "39.99"
"2" "The Fellowship of the Ring" "J.R.R. Tolkien" "423" "1954-07-29" "49.99"
"3" "The Two Towers" "J.R.R. Tolkien" "352" "1954-11-11" "49.99"
"4" "The Return of the King" "J.R.R. Tolkien" "416" "1955-10-20" "49.99"
sqlite>
Added in each row
In this type, each row has the column name as some form of the row.
- Insert
.mode insert
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode insert
sqlite> .headers on
sqlite> select * from books;
INSERT INTO "table"(id,title,author,pages,release_date,price) VALUES(1,'The Hobbit','J.R.R. Tolkien',310,'1937-09-21',39.99000000000000198);
INSERT INTO "table"(id,title,author,pages,release_date,price) VALUES(2,'The Fellowship of the Ring','J.R.R. Tolkien',423,'1954-07-29',49.99000000000000198);
INSERT INTO "table"(id,title,author,pages,release_date,price) VALUES(3,'The Two Towers','J.R.R. Tolkien',352,'1954-11-11',49.99000000000000198);
INSERT INTO "table"(id,title,author,pages,release_date,price) VALUES(4,'The Return of the King','J.R.R. Tolkien',416,'1955-10-20',49.99000000000000198);
sqlite> .headers off
sqlite> select * from books;
INSERT INTO "table" VALUES(1,'The Hobbit','J.R.R. Tolkien',310,'1937-09-21',39.99000000000000198);
INSERT INTO "table" VALUES(2,'The Fellowship of the Ring','J.R.R. Tolkien',423,'1954-07-29',49.99000000000000198);
INSERT INTO "table" VALUES(3,'The Two Towers','J.R.R. Tolkien',352,'1954-11-11',49.99000000000000198);
INSERT INTO "table" VALUES(4,'The Return of the King','J.R.R. Tolkien',416,'1955-10-20',49.99000000000000198);
sqlite>
No effect
These modes show the headers or column names irrespective of the .headers
flag, as for these modes the headers form quite a bit of structure to the output they are showing.
- Box
.mode box
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode box
sqlite> .headers on
sqlite> select * from books;
┌────┬────────────────────────────┬────────────────┬───────┬──────────────┬───────┐
│ id │ title │ author │ pages │ release_date │ price │
├────┼────────────────────────────┼────────────────┼───────┼──────────────┼───────┤
│ 1 │ The Hobbit │ J.R.R. Tolkien │ 310 │ 1937-09-21 │ 39.99 │
│ 2 │ The Fellowship of the Ring │ J.R.R. Tolkien │ 423 │ 1954-07-29 │ 49.99 │
│ 3 │ The Two Towers │ J.R.R. Tolkien │ 352 │ 1954-11-11 │ 49.99 │
│ 4 │ The Return of the King │ J.R.R. Tolkien │ 416 │ 1955-10-20 │ 49.99 │
└────┴────────────────────────────┴────────────────┴───────┴──────────────┴───────┘
sqlite> .headers off
sqlite> select * from books;
┌────┬────────────────────────────┬────────────────┬───────┬──────────────┬───────┐
│ id │ title │ author │ pages │ release_date │ price │
├────┼────────────────────────────┼────────────────┼───────┼──────────────┼───────┤
│ 1 │ The Hobbit │ J.R.R. Tolkien │ 310 │ 1937-09-21 │ 39.99 │
│ 2 │ The Fellowship of the Ring │ J.R.R. Tolkien │ 423 │ 1954-07-29 │ 49.99 │
│ 3 │ The Two Towers │ J.R.R. Tolkien │ 352 │ 1954-11-11 │ 49.99 │
│ 4 │ The Return of the King │ J.R.R. Tolkien │ 416 │ 1955-10-20 │ 49.99 │
└────┴────────────────────────────┴────────────────┴───────┴──────────────┴───────┘
sqlite>
- JSON
.mode json
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode json
sqlite> .headers on
sqlite> select * from books;
[{"id":1,"title":"The Hobbit","author":"J.R.R. Tolkien","pages":310,"release_date":"1937-09-21","price":39.99000000000000198},
{"id":2,"title":"The Fellowship of the Ring","author":"J.R.R. Tolkien","pages":423,"release_date":"1954-07-29","price":49.99000000000000198},
{"id":3,"title":"The Two Towers","author":"J.R.R. Tolkien","pages":352,"release_date":"1954-11-11","price":49.99000000000000198},
{"id":4,"title":"The Return of the King","author":"J.R.R. Tolkien","pages":416,"release_date":"1955-10-20","price":49.99000000000000198}]
sqlite> .headers off
sqlite> select * from books;
[{"id":1,"title":"The Hobbit","author":"J.R.R. Tolkien","pages":310,"release_date":"1937-09-21","price":39.99000000000000198},
{"id":2,"title":"The Fellowship of the Ring","author":"J.R.R. Tolkien","pages":423,"release_date":"1954-07-29","price":49.99000000000000198},
{"id":3,"title":"The Two Towers","author":"J.R.R. Tolkien","pages":352,"release_date":"1954-11-11","price":49.99000000000000198},
{"id":4,"title":"The Return of the King","author":"J.R.R. Tolkien","pages":416,"release_date":"1955-10-20","price":49.99000000000000198}]
sqlite>
- Line
.mode line
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode line
sqlite> .headers on
sqlite> select * from books;
id = 1
title = The Hobbit
author = J.R.R. Tolkien
pages = 310
release_date = 1937-09-21
price = 39.99
id = 2
title = The Fellowship of the Ring
author = J.R.R. Tolkien
pages = 423
release_date = 1954-07-29
price = 49.99
id = 3
title = The Two Towers
author = J.R.R. Tolkien
pages = 352
release_date = 1954-11-11
price = 49.99
id = 4
title = The Return of the King
author = J.R.R. Tolkien
pages = 416
release_date = 1955-10-20
price = 49.99
sqlite> .headers off
sqlite> select * from books;
id = 1
title = The Hobbit
author = J.R.R. Tolkien
pages = 310
release_date = 1937-09-21
price = 39.99
id = 2
title = The Fellowship of the Ring
author = J.R.R. Tolkien
pages = 423
release_date = 1954-07-29
price = 49.99
id = 3
title = The Two Towers
author = J.R.R. Tolkien
pages = 352
release_date = 1954-11-11
price = 49.99
id = 4
title = The Return of the King
author = J.R.R. Tolkien
pages = 416
release_date = 1955-10-20
price = 49.99
sqlite>
- Markdown
.mode markdown
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode markdown
sqlite> .headers on
sqlite> select * from books;
| id | title | author | pages | release_date | price |
|----|----------------------------|----------------|-------|--------------|-------|
| 1 | The Hobbit | J.R.R. Tolkien | 310 | 1937-09-21 | 39.99 |
| 2 | The Fellowship of the Ring | J.R.R. Tolkien | 423 | 1954-07-29 | 49.99 |
| 3 | The Two Towers | J.R.R. Tolkien | 352 | 1954-11-11 | 49.99 |
| 4 | The Return of the King | J.R.R. Tolkien | 416 | 1955-10-20 | 49.99 |
sqlite> .headers off
sqlite> select * from books;
| id | title | author | pages | release_date | price |
|----|----------------------------|----------------|-------|--------------|-------|
| 1 | The Hobbit | J.R.R. Tolkien | 310 | 1937-09-21 | 39.99 |
| 2 | The Fellowship of the Ring | J.R.R. Tolkien | 423 | 1954-07-29 | 49.99 |
| 3 | The Two Towers | J.R.R. Tolkien | 352 | 1954-11-11 | 49.99 |
| 4 | The Return of the King | J.R.R. Tolkien | 416 | 1955-10-20 | 49.99 |
sqlite>
- Table
.mode table
.headers on
select * from books;
.headers off
select * from books;
Output:
sqlite> .mode table
sqlite> .headers on
sqlite> select * from books;
+----+----------------------------+----------------+-------+--------------+-------+
| id | title | author | pages | release_date | price |
+----+----------------------------+----------------+-------+--------------+-------+
| 1 | The Hobbit | J.R.R. Tolkien | 310 | 1937-09-21 | 39.99 |
| 2 | The Fellowship of the Ring | J.R.R. Tolkien | 423 | 1954-07-29 | 49.99 |
| 3 | The Two Towers | J.R.R. Tolkien | 352 | 1954-11-11 | 49.99 |
| 4 | The Return of the King | J.R.R. Tolkien | 416 | 1955-10-20 | 49.99 |
+----+----------------------------+----------------+-------+--------------+-------+
sqlite> .headers off
sqlite> select * from books;
+----+----------------------------+----------------+-------+--------------+-------+
| id | title | author | pages | release_date | price |
+----+----------------------------+----------------+-------+--------------+-------+
| 1 | The Hobbit | J.R.R. Tolkien | 310 | 1937-09-21 | 39.99 |
| 2 | The Fellowship of the Ring | J.R.R. Tolkien | 423 | 1954-07-29 | 49.99 |
| 3 | The Two Towers | J.R.R. Tolkien | 352 | 1954-11-11 | 49.99 |
| 4 | The Return of the King | J.R.R. Tolkien | 416 | 1955-10-20 | 49.99 |
+----+----------------------------+----------------+-------+--------------+-------+
sqlite>