transaction_timestamp()

一个返回当前事务开始时间的函数

transaction_timestamp() 是一个系统函数,它返回一个时间戳,表示当前事务开始的时间点。

transaction_timestamp() 是在 PostgreSQL 8.2 中添加的。

用法

transaction_timestamp ( ) → timestamp with time zone

历史上,函数 current_timestamp 返回当前事务的开始时间;transaction_timestamp() 被添加为更不易混淆的别名

变更历史

示例

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)

如果一个语句在一个显式事务之外执行,那么 transcation_timestamp() 返回的时间戳将与 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)

分类

日期和时间, 系统函数

另请参阅

clock_timestamp(), current_timestamp, now(), statement_timestamp()

反馈

提交关于“transaction_timestamp()”的任何评论、建议或更正,请在此处提交