PostgreSQL transaction_timestamp() Function

The PostgreSQL transaction_timestamp() function returns the system date and time when the current transaction started.

The PostgreSQL transaction_timestamp() function is equivalent to now() and current_timestamp().

transaction_timestamp() Syntax

Here is the syntax of the PostgreSQL transaction_timestamp() function:

transaction_timestamp() -> timestamp


The PostgreSQL transaction_timestamp() function does not require any parameters.

Return value

The PostgreSQL transaction_timestamp() function returns a date and time with time zone information, which is the system date and time when the transaction in which the function is located started executing.

That is, all transaction_timestamp() functions in a transaction return the same value, it is different from clock_timestamp().

transaction_timestamp() Examples

This example shows how to use the PostgreSQL transaction_timestamp() function to get the current date and time.

SELECT transaction_timestamp();
 2022-05-15 22:17:34.819513+03

The transaction_timestamp() function returns the time when the statement in which it was executed started, not the time when the function was executed. See the example below:

-[ RECORD 1 ]---------------------------
transaction_timestamp      | 2022-05-15 22:18:31.076406+03
pg_sleep |
transaction_timestamp      | 2022-05-15 22:18:31.076406+03

Here, even though we use pg_sleep(1) to pause execution for 1 second between the two transaction_timestamp() functions, the values returned by both transaction_timestamp() functions is still the same.