DEFAULT is often used for date and time columns. A very common situation is to use the current date and time for the default value. In PostgreSQL, you use the function
CURRENT_TIMESTAMP to get the current date and time.
create_timestamp column of the
author table has a default value of
CURRENT_TIMESTAMP. This statement ...
INSERT INTO author (id, last_name, photo, create_timestamp) VALUES
(7, 'Smith', 'imgs/Smith2.jpg', DEFAULT);
... inserts a row where the
create_timestamp column is given the current date and time – i.e. the date and time when the record was inserted. Here is the result:
Notice that the first name is not given in this query. The value for
NULL because there is no
DEFAULT value for this column.