localtimestamp

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

localtimestamp 是一个系统函数,返回当前事务开始时的 timestamp,不带时区。

localtimestampPostgreSQL 7.3 中添加。

用法

localtimestamp → timestamp
localtimestamp ( integer ) → timestamp

可选的 integer 参数决定了秒字段中小数位的精度。

对于返回 timestamp with time zone 的等效函数,请参见 current_timestamp

变更历史

示例

localtimestamp 的基本用法示例

postgres=# SELECT localtimestamp;
       localtimestamp       
----------------------------
 2022-12-30 11:13:39.167389
(1 row)

指定精度

postgres=# SELECT localtimestamp(0);
   localtimestamp    
---------------------
 2022-12-30 11:14:38
(1 row)

postgres=# SELECT localtimestamp(3);
     localtimestamp      
-------------------------
 2022-12-30 11:14:40.631
(1 row)

大于 6 的精度将被向下舍入

postgres=# SELECT localtimestamp(7);
WARNING:  TIMESTAMP(7) precision reduced to maximum allowed, 6
       localtimestamp       
----------------------------
 2022-12-30 11:15:47.828753
(1 row)

分类

日期和时间, 系统函数

另请参阅

localtime, current_timestamp

反馈

提交任何关于“localtimestamp”的评论、建议或更正请点击 这里