PostgreSQL – TRANSACTION_TIMESTAMP

In PostgreSQL, transaction_timestamp() is a built-in function that returns the current timestamp (including both date and time) of the start of the current transaction. This function is often used in SQL queries and transactions to record the timestamp when a particular operation or transaction began.

Here’s how you can use transaction_timestamp():

SELECT transaction_timestamp();

The result will be a timestamp in the format ‘YYYY-MM-DD HH:MI:SS’. For example:

2023-09-21 14:30:00

statement_timestamp() is the time at which the statement was executed. transaction_timestamp() is the time at which the transaction began – i.e. the time at which the BEGIN statement was executed.

You can use this function to record the start time of a transaction in a table or use it in SQL statements to compare timestamps or perform other operations within a transaction context. transaction_timestamp will remain the same throughout the entire transaction.

Similar Posts