在PostgreSQL中,我使用now()
和current_timestamp
函数,没有区别:
# SELECT now(), current_timestamp;
now | now
--------------------------------+--------------------------------
04/20/2014 19:44:27.215557 EDT | 04/20/2014 19:44:27.215557 EDT
(1 row)
我是不是遗漏了什么?
发布于 2016-12-09 16:49:43
此外,当您正确使用它们时,它们没有功能上的差异,因此它们被不同地铸造:
'now()'
重新识别(就像'today'
或'now'
一样):
b=# select 'now()'::timestamptz;
timestamptz
-------------------------------
2016-12-09 16:31:35.942243+00
(1 row)
'CURRENT_TIMESTAMP'
给出来自黑暗边缘的有趣错误
注意:在PostgreSQL版本7.2中,“current”不再支持作为日期/时间常数。
b=# select 'CURRENT_TIMESTAMP'::timestamptz;
ERROR: date/time value "current" is no longer supported
LINE 1: select 'CURRENT_TIMESTAMP'::timestamptz;
^
而'transaction_timestamp()'
只是不被重新定义为具有tz值的时间戳:
b=# select 'transaction_timestamp()'::timestamptz;
ERROR: invalid input syntax for type timestamp with time zone: "transaction_timestamp()"
LINE 1: select 'transaction_timestamp()'::timestamptz;
^
请不要问为什么你要投'now()' as timestamp
。我在人的代码中看到了where timestamp_column = 'now()'
而不是where timestamp_column = now()
,所以我认为这种澄清将是有趣的事实,也是Erwin的答案的好补充。
https://dba.stackexchange.com/questions/63548
复制相似问题