Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display `Null` (SQLite)

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"?

like image 911
Kai - Kazuya Ito Avatar asked Oct 17 '25 00:10

Kai - Kazuya Ito


1 Answers

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
like image 187
Kai - Kazuya Ito Avatar answered Oct 18 '25 20:10

Kai - Kazuya Ito



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!