Contents
clock_timestamp()
clock_timestamp()
is a system function returning a timestamp representing the point-in-time the function was executed.
clock_timestamp()
was added in PostgreSQL 8.2.
Usage
clock_timestamp ( ) → timestamp with time zone
clock_timestamp()
returns the time and date current when the function was executed. In contrast to current_timestamp
, which returns the time and date current at the start of the current transaction, the value returned by clock_timestamp()
will change for each execution of the function.
Change history
- PostgreSQL 8.2
- added (commit e6004f01)
Examples
Basic execution example for clock_timestamp()
:
postgres=# SELECT clock_timestamp(); clock_timestamp ------------------------------- 2021-06-17 16:08:07.867682+01 (1 row)
The timestamp returned by clock_timestamp()
will increase each time the function is executed within a query:
postgres=# SELECT clock_timestamp(), statement_timestamp(), current_timestamp, clock_timestamp()\gx -[ RECORD 1 ]-------+------------------------------ clock_timestamp | 2021-06-17 16:12:37.167085+01 statement_timestamp | 2021-06-17 16:12:37.166871+01 current_timestamp | 2021-06-17 16:12:37.166871+01 clock_timestamp | 2021-06-17 16:12:37.167086+01
In the above query, the values reported for statement_timestamp()
and current_timestamp
represent the point-in-time when statement execution started, and hence report an earlier time than the first invocation of clock_timestamp()
.
References
- PostgreSQL documentation: Date/Time Functions
- PostgreSQL documentation: Current Date/Time