Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Default values
6. Inserting DEFAULT values by omitting columns
How to auto-generate values in a database


Very nice! Now, what if you need to add a default value to more than one column? Here's how you can do it:

INSERT INTO author (id, first_name, last_name, photo, create_timestamp, is_active) VALUES
(3, 'Alan', 'Hillary', DEFAULT, DEFAULT, DEFAULT);

Wherever we want the database to insert the default value, we put DEFAULT.

Since we used more than one DEFAULT in this statement, it got quite long! Fortunately, PostgreSQL provides a shorter version that we can use:

INSERT INTO author (id, first_name, last_name) VALUES
(3, 'Alan', 'Hillary');

Notice that PostgreSQL allows you to omit DEFAULTs in the VALUES list. In the column list, you can also skip any columns where you'd put a DEFAULT value. If you have to insert multiple DEFAULT values, it's easier and quicker to omit them, as we did here.


Martin Williams (id = 4) registered to join the site on 2018-09-30. Insert his data with default values for the photo and is_active columns.