Question

How to get a real time within PostgreSQL transaction?

As far as I understand now() returns the same time during the whole PostgreSQL transaction? But how to get real time?

Also, I am interested if there any configuration parameter to limit duration of transaction, so that after this period expiration transaction would immediately fail or somehow else prohibit following queries?

 45  21714  45
1 Jan 1970

Solution

 120

Use clock_timestamp().

now() is a traditional PostgreSQL equivalent to transaction_timestamp(), which is equivalent to CURRENT_TIMESTAMP. These functions return the start time of the current transaction. Their values do not change during the transaction.

statement_timestamp() returns the time of receipt of the latest command message from the client.

clock_timestamp() returns the actual current time, and therefore its value changes even within a single SQL command.

For more information see the documentation.

2014-06-11

Solution

 1
Timeofday()

May work for you.

2010-07-29