current_date 是一个系统函数,它返回当前事务开始时的 date。
current_date 在 PostgreSQL 6.3 中被添加。
用法
current_date → date
尽管其名称如此,current_date 返回的是当前事务开始的日期,而不是函数实际执行的日期(后者可以通过 clock_timestamp() 来检索)。
请注意,current_date 不能被调用为 current_date()。
变更历史
- PostgreSQL 6.2
- 已添加(提交 f10b6392)
示例
current_date 的基本执行示例
postgres=# SELECT current_date; current_date -------------- 2021-06-17 (1 row)
current_date 始终报告与 transaction_timestamp() 相同的日期,并且(如果在一个隐式事务中执行)与 statement_timestamp() 相同的日期。
postgres=# SELECT
current_date,
transaction_timestamp(),
statement_timestamp(),
clock_timestamp()\gx
-[ RECORD 1 ]---------+------------------------------
current_date | 2021-06-19
transaction_timestamp | 2021-06-19 08:48:18.386946+09
statement_timestamp | 2021-06-19 08:48:18.386946+09
clock_timestamp | 2021-06-19 08:48:18.387096+09
实际上,所有这些函数返回的日期通常是相同的,但对于在一天快结束时开始的事务,可能会有所不同。
变体 current_date() 无效
postgres=# SELECT current_date();
ERROR: syntax error at or near "("
LINE 1: SELECT current_date();
^
