There are various methods to retrieve the current time in PostgreSQL. These methods include:
The value
current_timestamp
The function
now()
The function
clock_timestamp()
Here are some examples using these methods in SQL code snippets:
1INSERT INTO person (id, name, created_at) VALUES ('33333333-3333-3333-3333-333333333005', 'Max' , current_timestamp);
2INSERT INTO person (id, name, created_at) VALUES ('33333333-3333-3333-3333-333333333005', 'Max' , now());
3INSERT INTO person (id, name, created_at) VALUES ('33333333-3333-3333-3333-333333333005', 'Max' , clock_timestamp());
All these methods will insert a timestamp into the database, but they work somewhat differently.
current_timestamp
is a value defined in Standard SQL. You can find more standard values in the PostgreSQL manual.
Both now()
and clock_timestamp()
are PostgreSQL functions. The main difference between them is that now()
adds the time at the start of the transactions, while clock_timestamp()
inserts the time at the execution of the statement.