current_time

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

current_time 是一个系统函数,它返回当前事务开始时的 time

current_time 添加于 PostgreSQL 6.3

用法

current_time → time with time zone

尽管其名称是 current_time,但它返回的是当前事务开始的时间,而不是函数实际执行的时间(后者可以通过 clock_timestamp() 来获取)。

该函数提供了一个变体 current_time(),用于检索具有指定精度的事务时间。

current_time ( integer ) → timestamp with time zone

请注意,current_time 不能以 current_time() 的方式调用。

变更历史

示例

current_time 的基本执行示例

postgres=# SELECT current_time;
    current_time    
--------------------
 20:22:38.562496+01
(1 row)

current_time 始终报告与 transaction_timestamp() 相同的时间,并且(如果在隐式事务中执行)与 statement_timestamp() 相同的时间。

postgres=# SELECT
              current_time,
              transaction_timestamp(),
              statement_timestamp(),
              clock_timestamp()\gx
-[ RECORD 1 ]---------+------------------------------
current_time          | 20:26:13.979644+01
transaction_timestamp | 2021-06-17 20:26:13.979644+01
statement_timestamp   | 2021-06-17 20:26:13.979644+01
clock_timestamp       | 2021-06-17 20:26:13.980394+01

可以(可选地)指定精度(小数位数)。

postgres=# SELECT current_time(3);
  current_time   
-----------------
 20:30:13.684+01
(1 row)

指定的精度必须在 06 之间;大于 6 的值将被减小到 6

postgres=# SELECT current_time(99);
WARNING:  TIME(99) WITH TIME ZONE precision reduced to maximum allowed, 6
    current_time    
--------------------
 20:31:02.153981+01
(1 row)

current_time() 变体无效。

postgres=# SELECT current_time();
ERROR:  syntax error at or near ")"
LINE 1: SELECT current_time();
                            ^

分类

日期和时间, 系统函数

另请参阅

current_timestamp, current_date, transaction_timestamp(), clock_timestamp(), localtime

反馈

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