Simplified
Simplified

L2.1What goes in an empty cell?

YOU

What goes in an empty cell?

Sign upEmailName (optional)Name (optional)ivy@simplified.orgusersidemailname7ben.k@simplified.orgBen8gus@simplified.orgGus9ivy@simplified.org0''
NULL
a cell that holds no value at all
your contactsnamephone numberemailAna555-0142ana@mail.comDan555-0163NULLInstagram profilesusernamebioleoCoffee and codeyouNULL
Sign upEmailName (optional)Name (optional)ivy@simplified.orgusersidemailname7ben.k@simplified.orgBen8gus@simplified.orgGus9ivy@simplified.orgNULL0''

Databases · Lesson 2.1

Empty Values

What goes in an empty cell?

Simplified
0:00 / 1:10

When you signed up for Simplified, Postgres added a row for you to its users table.

It generated your id, and stored the email you log in with.

Say Simplified's sign-up form marks the name field as optional, like many forms do.

A new learner types just their email, ivy@simplified.org, and skips the name.

Postgres adds their row, and generates their id, 9.

Sign upEmailName (optional)Name (optional)ivy@simplified.orgusersidemailname7ben.k@simplified.orgBen8gus@simplified.orgGus9ivy@simplified.org?0''

So what goes in their name cell?

Not 0, because then their name would be 0.

And not an empty string, which is text with no characters.

That would say their name is blank, but they just didn't give one.

So Postgres leaves the cell with no value at all.

This is called NULL.

NULL means a cell holds no value at all.

Sign upEmailName (optional)Name (optional)ivy@simplified.orgusersidemailname7ben.k@simplified.orgBen8gus@simplified.orgGus9ivy@simplified.orgNULL0''

Think of the contacts on your phone, kept in rows and columns.

Say you save a new contact, Dan, with just his phone number.

You never typed an email, so his email cell would be NULL.

And say you never wrote a bio on Instagram.

Instagram might leave your bio cell NULL too.

your contactsnamephone numberemailAna555-0142ana@mail.comDan555-0163NULLInstagram profilesusernamebioleoCoffee and codeyouNULL

NULL means no value at all: not 0, and not an empty string.

It says no value is there, because nobody gave one.

Example: What goes in an empty cell?

A new learner signs up for Simplified with only an email, kim@simplified.org, and skips the optional name. Postgres generates their id, 11.

What is in their name cell?

Explanation

First, the name is optional, so the learner can leave it out.

Then, the learner gave no name, and Postgres doesn't store 0 or an empty string in its place.

Therefore, their name cell is NULL.

Question 1

Say Amazon keeps each review's star rating in a column, and one review's rating cell is NULL.

What does that NULL say about the rating?

How Postgres requires a value

Sign upEmailName (optional)Name (optional)ivy@simplified.orgusersidemailname7ben.k@simplified.orgBen8gus@simplified.orgGus9ivy@simplified.orgNULL0''
usersidemailnamexpcreated_atprimary keyNOT NULLNOT NULLNOT NULLSign upEmailName (optional)Jorefused
NOT NULL
a column that must hold a value in every row
usersidemailnamexpcreated_atprimary keyNOT NULLNOT NULLNOT NULLSign upEmailName (optional)Jorefused
Instagram profilesusernamebioleoCoffee and codeyouNULLNOT NULLWhatsApp accountsphone numbername555-0142Ana555-0163DanNOT NULL
usersidemailnamexpcreated_atprimary keyNOT NULLNOT NULLNOT NULLSign upEmailName (optional)Jorefused

Databases · Lesson 2.2

Empty Values

How Postgres requires a value

Simplified
0:00 / 1:15

So when Ivy skipped the optional name, Postgres stored NULL in her name cell.

Her email, ivy@simplified.org, is how she logs in.

Sign upEmailName (optional)Name (optional)ivy@simplified.orgusersidemailname7ben.k@simplified.orgBen8gus@simplified.orgGus9ivy@simplified.orgNULL0''

But what if a learner skips their email too?

Then Simplified would have no way to log them in.

So the email column has a rule that forbids NULL.

This rule is called NOT NULL.

A column with NOT NULL must hold a value in every row.

So Postgres refuses a sign-up with no email, and nothing is stored, just like 'lots' in xp.

The xp and created at columns have NOT NULL too, and id is a primary key, so never empty.

So name is the one column that can be NULL.

usersidemailnamexpcreated_atprimary keyNOT NULLNOT NULLNOT NULLSign upEmailName (optional)Jorefused

So which columns get NOT NULL on other apps?

Instagram profilesusernamebioleoCoffee and codeyouNULLNOT NULLNULLWhatsApp accountsphone numbername555-0142Ana555-0163DanNOT NULL

Instagram might put NOT NULL on its username column.

Every profile needs a username, so people can find it.

But its bio column can stay without the rule, so a bio you never wrote is NULL.

WhatsApp might put NOT NULL on its phone number column.

You can't sign up for WhatsApp without a phone number, because that's how friends reach you.

So a column gets NOT NULL when every row needs that value to work.

And a value someone may skip goes in a column without it, where it can be NULL.

Example: How Postgres requires a value

Say Simplified gets 3 sign-ups. Two give an email and a name. The third gives only a name, Jo.

How many new rows does users get?

Explanation

First, the email column has NOT NULL, so every row must hold an email.

Then, Jo gave no email, so Postgres refuses that sign-up, and stores nothing.

Therefore, users gets 2 new rows.

Question 1

Say Spotify's accounts table has an email column with the NOT NULL rule. One morning, 7 sign-ups arrive: 5 with an email, and 2 without one.

How many new rows does the table get?

rows

Question 2

Say Instagram's profiles table has username and email columns with NOT NULL, and bio and website columns without it. You sign up with just a username and an email.

Which cells of your row are NULL?

Question 3

Simplified's users table has NOT NULL on email, xp and created_at, and none on name.

Which of these sign-ups does Postgres refuse?

Question 4

Say Instagram's profiles table has NOT NULL on username and none on bio. 10 people sign up: 6 give a username and a bio, 3 give only a username, and 1 gives only a bio.

How many new rows does the table get?

rows

Question 5

Say Venmo keeps its users in a table with a phone number column and a profile photo column. Venmo needs every user's phone number to send them a code when they log in. Users may skip the profile photo.

Which column should get NOT NULL?

Question 6

A table's email column has NOT NULL.

Which of these can never happen?

How Postgres fills in a value

Sign upEmailivy@simplified.orgName (optional)usersidemailnamexpcreated_atNOT NULLNOT NULLNOT NULL9ivy@simplified.orgNULLNULLNULL?
Instagram0followersDuolingo0 daysstreakInstagramNov 2026date joined
DEFAULT
the value a column gets when a new row leaves it out
usersidemailnamexpcreated_at9ivy@simplified.orgNULLDEFAULT 0DEFAULT now()02026-11-04 09:30signed up Nov 4, 2026, 9:30 am
Instagram accountsusernamefollowersDEFAULT 0new_account0Duolingo streakslearnerstreakDEFAULT 0new_learner0
new row givesemail: test@…name: Testxp: 50usersidemailnamexpcreated_atDEFAULT 0DEFAULT now()13test@simplified.orgTest502026-11-04 10:15
emailnamexpcreated_atNOT NULLDEFAULTleft out✓✓0now()0now()✓nonerefusednoneNULL

Databases · Lesson 2.3

Empty Values

How Postgres fills in a value

Simplified
0:00 / 2:10

Postgres refuses a sign-up with no email, because the email column has NOT NULL.

The xp column has NOT NULL too, so every row must hold a number there.

But the sign-up form asks for an email and a name, never for XP.

So learner 9's row left xp out, and xp would be NULL.

The same goes for created at: the form never asks when you signed up.

Sign upEmailivy@simplified.orgName (optional)usersidemailnamexpcreated_atNOT NULLNOT NULLNOT NULL9ivy@simplified.orgNULLNULLNULL?

So how did learner 9's row get past NOT NULL?

Well, you've seen new accounts start with values nobody typed.

A new Instagram account starts at 0 followers.

A new Duolingo streak starts at 0 days.

And Instagram fills in the date you joined, without asking you.

Instagram0followersDuolingo0 daysstreakInstagramNov 2026date joined

Postgres can do the same for a column.

This is called a DEFAULT.

A DEFAULT is the value a column gets when a new row leaves it out.

Simplified's xp column has a DEFAULT of 0.

So learner 9's row gets 0 in xp, and Postgres doesn't refuse it.

And created at has a DEFAULT of now(), the time the row is added.

Say learner 9 signed up at 9:30 am on November 4, 2026.

So their created at is filled in as 2026-11-04 09:30.

usersidemailnamexpcreated_at9ivy@simplified.orgNULLDEFAULT 0DEFAULT now()02026-11-04 09:30signed up Nov 4, 2026, 9:30 am

Instagram might give its followers column a DEFAULT of 0, too.

And Duolingo might give a new streak a DEFAULT of 0.

Instagram accountsusernamefollowersDEFAULT 0new_account0Duolingo streakslearnerstreakDEFAULT 0new_learner0

Now what if a new row does give a value for that column?

Say a Simplified developer adds a test learner with 50 XP, to check how the Learn page shows it.

The row gives xp as 50, so Postgres stores 50, not 0.

A value given beats the default.

The row leaves out created at, so that still gets now().

new row givesemail: test@…name: Testxp: 50usersidemailnamexpcreated_atDEFAULT 0DEFAULT now()13test@simplified.orgTest502026-11-04 10:15

And what about a column with no DEFAULT?

The name column has none, so a row that leaves it out gets NULL, like learner 9's.

The email column has no DEFAULT either, but it has NOT NULL.

So a row that leaves out email is refused.

emailnamexpcreated_atNOT NULLDEFAULTleft out✓✓0now()0now()✓nonerefusednoneNULL

So a column a new row leaves out gets its DEFAULT, if it has one.

With no DEFAULT, it gets NULL, or the row is refused if the column is NOT NULL.

Example: How Postgres fills in a value

Learner 12 signs up for Simplified with an email and a name. The new row leaves out xp, which is NOT NULL with a DEFAULT of 0.

What is learner 12's xp?

Explanation

First, the row leaves xp out, so Postgres looks for xp's DEFAULT.

Then, xp's DEFAULT is 0, so Postgres fills in 0, and NOT NULL is met.

Therefore, learner 12's xp is 0.

Question 1

Simplified's users table has 6 rows. Its xp column has NOT NULL and a DEFAULT of 0. Then 3 new learners sign up, and each new row leaves xp out.

How many rows does the table have now?

rows

Question 2

A users table's created_at column has NOT NULL and a DEFAULT of now(), the time the row is added. One learner signs up at 8:45 am on December 1, 2026. A second learner signs up at 8:55 am the same day. Both rows leave created_at out.

What is in the second learner's created_at cell?

Question 3

Say Instagram's accounts table has a followers column with a DEFAULT of 0. A developer adds 3 test accounts. The first account's row gives followers as 250. The other two rows leave followers out.

How many followers do the 3 test accounts have in all?

followers

Question 4

Say Spotify's accounts table has a phone column with no DEFAULT and no NOT NULL rule. A new account's row leaves phone out.

What goes in its phone cell?

Question 5

A users table has five columns: id, generated by Postgres; email, NOT NULL with no DEFAULT; name, with no DEFAULT and no NOT NULL; xp, NOT NULL with a DEFAULT of 0; and created_at, NOT NULL with a DEFAULT of now(). A new row gives only an email.

How many of its cells are NULL?

cells

Question 6

Say a Duolingo table's streak column has NOT NULL, but no DEFAULT. A new learner's row leaves streak out.

What happens?

Assistant

Highlight lesson text and click Ask AI, or type a question below.