How to get a real time within PostgreSQL transaction?

后端 未结 3 1192
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 11:14

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

3条回答
  •  执念已碎
    2021-01-01 12:01

    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.

提交回复
热议问题