now() 是一个系统函数,返回当前事务的时间戳。
now() 在 PostgreSQL 6.1 中添加。
用法
now ( ) → timestamp with time zone
now() 等同于 transaction_timestamp() 和符合 SQL 标准的 current_timestamp。
请注意,尽管名称是 now(),但它返回的是当前事务开始时的时间点,而不是函数实际执行的时间。当前时间可以使用 clock_timestamp() 获取。
变更历史
- PostgreSQL 6.1
- 添加于 (提交 071484c5)
示例
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)
