Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Inserting data
4. Insert partial data
Modifying data
Deleting data
CRUD

Instruction

You learn quickly, great!

Sometimes you don't know all the data when you insert information into a database. PostgreSQL allows you to insert data with values for some columns and omit data for other columns at the same time.

To insert Chris of unknown age as a user with an ID of 6, use the command:

INSERT INTO user (id, name) VALUES
(6, 'Chris');

The new part after the table user, (id, name), is the list of column names you will give values to. The expression (6, 'Chris'), in turn, is the list of values for these columns. The number 6 is the value of the first specified column, id. The text 'Chris' is the value of the second specified column, name. The value for unknown in SQL is NULL. A database inserts NULL values for each column you omit in an INSERT statement.

Warning: Sometimes, the database will not allow you to add incomplete data. This topic is beyond the scope of this course; we talk about it in the Creating Tables in SQL course.

Exercise

Balkan cuisine is getting popular, so we need another Balkan item on the menu.

Add Kosovo Bread with ID of 10; it's a starter. We have yet to decide on the price, so omit it for now.

Stuck? Here's a hint!

Type:

INSERT INTO dish (id, type, name) VALUES
(10, 'starter', 'Kosovo Bread');