localtimestamp 是一个系统函数,返回当前事务开始时的 timestamp,不带时区。
localtimestamp 于 PostgreSQL 7.3 中添加。
用法
localtimestamp → timestamp
localtimestamp ( integer ) → timestamp
可选的 integer 参数决定了秒字段中小数位的精度。
对于返回 timestamp with time zone 的等效函数,请参见 current_timestamp。
变更历史
- PostgreSQL 7.3
- 添加于 (提交 133df7ce)
示例
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)
参考资料
- PostgreSQL 文档: 日期/时间函数
