Contents
statement_timestamp()
A function returning the point-in-time the current query started
statement_timestamp()
is a system function returning a timestamp representing the point-in-time at which the current statement started.
statement_timestamp()
was added in PostgreSQL 8.2.
Usage
statement_timestamp ( ) → timestamp with time zone
The value returned is the time of receipt of the latest command message from the client. If it is the first and only statement in a transaction, the value returned will be the same as the value returned by transaction_timestamp()
/ current_timestamp
.
Change history
- PostgreSQL 8.2
- added (commit e6004f01)
Examples
Basic execution example for statement_timestamp()
:
postgres=# SELECT statement_timestamp(); statement_timestamp ------------------------------- 2021-06-17 17:51:41.791603+01 (1 row)
With a statement executed outside of an explicit transaction, the timestamp returned by statement_timestamp()
is identical to that returned by transaction_timestamp()
:
postgres=# SELECT transaction_timestamp(), statement_timestamp(), clock_timestamp(), clock_timestamp()\gx -[ RECORD 1 ]---------+------------------------------ transaction_timestamp | 2021-06-17 18:06:45.891294+01 statement_timestamp | 2021-06-17 18:06:45.891294+01 clock_timestamp | 2021-06-17 18:06:45.891497+01 clock_timestamp | 2021-06-17 18:06:45.891497+01
The same query executed in an explicit transaction:
postgres=# BEGIN; BEGIN postgres=*# SELECT transaction_timestamp(), statement_timestamp(), clock_timestamp(), clock_timestamp()\gx -[ RECORD 1 ]---------+------------------------------ transaction_timestamp | 2021-06-17 18:09:28.23169+01 statement_timestamp | 2021-06-17 18:09:30.726471+01 clock_timestamp | 2021-06-17 18:09:30.726765+01 clock_timestamp | 2021-06-17 18:09:30.726766+01
References
- PostgreSQL documentation: Date/Time Functions
- PostgreSQL documentation: Current Date/Time