now()

返回当前事务时间戳的函数

now() 是一个系统函数,返回当前事务的时间戳。

now()PostgreSQL 6.1 中添加。

用法

now ( ) → timestamp with time zone

now() 等同于 transaction_timestamp() 和符合 SQL 标准的 current_timestamp

请注意,尽管名称是 now(),但它返回的是当前事务开始时的时间点,而不是函数实际执行的时间。当前时间可以使用  clock_timestamp() 获取。

变更历史

示例

now() 的基本用法示例

postgres=# SELECT now();
              now
-------------------------------
 2023-06-28 19:04:29.844058+02
(1 row)

注意,now() 返回的不是字面意义上的“现在”时间,而是当前事务的开始时间

postgres=# BEGIN;
BEGIN

postgres=*# SELECT now(), clock_timestamp(); now | clock_timestamp -------------------------------+------------------------------- 2023-06-28 19:07:21.116916+02 | 2023-06-28 19:07:29.973033+02 (1 row) postgres=*# SELECT pg_sleep(1); pg_sleep ---------- (1 row) postgres=*# SELECT now(), clock_timestamp(); now | clock_timestamp -------------------------------+------------------------------- 2023-06-28 19:07:21.116916+02 | 2023-06-28 19:07:35.082246+02 (1 row)

分类

日期和时间, 系统函数

另请参阅

transaction_timestamp(), current_timestamp, clock_timestamp()

反馈

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