4

On SQLite, I displayed the table "user" as shown below but "Null" is not displayed so I cannot differentiate between "Null" and Blank(Empty String):

sqlite> .header on sqlite> .mode box sqlite> select * from user; ┌────┬─────────────────┐ │ id │ name │ ├────┼─────────────────┤ │ 1 │ Steve Jobs │ │ 2 │ │ <- Null │ 3 │ │ <- Null │ 4 │ Bill Gates │ │ 5 │ │ <- Blank(Empty String) │ 6 │ Mark Zuckerberg │ └────┴─────────────────┘ 

Are there any ways to display "Null"?

1 Answer 1

8

This command below can set what to show for NULL values:

.nullvalue <String> 

So, set NULL as shown below:

.nullvalue NULL 

Then, NULL is displayed for NULL values as shown below:

sqlite> .headers on sqlite> .mode box sqlite> SELECT * FROM person; ┌────┬─────────────────┐ │ id │ name │ ├────┼─────────────────┤ │ 1 │ Steve Jobs │ │ 2 │ NULL │ <- NULL │ 3 │ NULL │ <- NULL │ 4 │ Bill Gates │ │ 5 │ │ <- Blank(Empty String) │ 6 │ Mark Zuckerberg │ └────┴─────────────────┘ 

Next, set This is NULL. as shown below:

.nullvalue "This is NULL." 

Then, This is NULL is displayed for NULL values as shown below:

sqlite> .headers on sqlite> .mode box sqlite> SELECT * FROM person; ┌────┬─────────────────┐ │ id │ name │ ├────┼─────────────────┤ │ 1 │ Steve Jobs │ │ 2 │ This is NULL. │ <- NULL │ 3 │ This is NULL. │ <- NULL │ 4 │ Bill Gates │ │ 5 │ │ <- Blank(Empty String) │ 6 │ Mark Zuckerberg │ └────┴─────────────────┘ 

And, these commands below can show the details of the command .nullvalue:

.help .nullvalue 

Or:

.help nullvalue 

Then, this is how it looks like below:

sqlite> .help .nullvalue .nullvalue STRING Use STRING in place of NULL values 
Sign up to request clarification or add additional context in comments.

1 Comment

And you can put these directives in ~/.sqliterc so they're always used.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.