Contents
transaction_timestamp()
A function returning the point-in-time the current transaction started
transaction_timestamp()
is a system function returning a timestamp representing the point-in-time at which the current transaction started.
transaction_timestamp()
was added in PostgreSQL 8.2.
Usage
transaction_timestamp ( ) → timestamp with time zone
Historically the function current_timestamp
returned the start time of the current transaction; transaction_timestamp()
was added as a less ambiguous alias.
Change history
- PostgreSQL 8.2
- added (commit e6004f01)
Examples
Basic execution example for transaction_timestamp()
:
postgres=# BEGIN; BEGIN postgres=*# SELECT transaction_timestamp(), statement_timestamp(); transaction_timestamp | statement_timestamp -------------------------------+------------------------------- 2021-06-17 18:22:12.555089+01 | 2021-06-17 18:23:17.327421+01 (1 row)
If a statement is executed outside of an explicit transaction, the timestamp returned by transcation_timestamp()
is identical to that returned by statement_timestamp()
:
postgres=# SELECT transaction_timestamp(), statement_timestamp(); transaction_timestamp | statement_timestamp ------------------------------+------------------------------ 2021-06-17 18:24:27.91313+01 | 2021-06-17 18:24:27.91313+01 (1 row)
References
- PostgreSQL documentation: Date/Time Functions
- PostgreSQL documentation: Current Date/Time