Instruction
Great! We've reached the final section for this part. Let's review what we've learned.
A database architect can define a default value for a column. You can use DEFAULTs ...
- ... in an
INSERTstatement:INSERT INTO author (id, first_name, last_name, photo, create_timestamp, is_active) VALUES (120, 'Gary', 'Brown', 'imgs/gary.jpg', '2018-08-25', DEFAULT);
- ... by omitting columns in
INSERT:INSERT INTO author (id, first_name, last_name) VALUES (121, 'Mary', 'Taylor');
- ... during an
UPDATEoperation:UPDATE author photo = DEFAULT WHERE id = 120;
Plus, you learned how to auto-generate unique values by:
- Using
SERIALand omitting the name of the ID column:INSERT INTO author(first_name, last_name) VALUES ('Stanley', 'Lewis'); - Using
DEFAULTto generate aSERIALvalue:INSERT INTO author VALUES (DEFAULT, 'Mark', 'Barker', 'imgs/barker1.jpg', DEFAULT, DEFAULT);
- Using a sequence:
INSERT INTO author (id, first_name, last_name, is_active) VALUES (NEXTVAL('id_seq', 'Miriam', 'Clerk', 1);
Remember, auto-generated values from the same sequence can be used in multiple tables and each value will be unique.
Exercise
Well done! You've completed Part 3 and learned the various ways PostgreSQL can automatically generate values.
Click to move on to Part 4.




