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

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)

Categories

Date and time, System function

See also

clock_timestamp(), current_timestamp, statement_timestamp()