# SELECT now(),current_timestamp; now | now --------------------------------+-------------------------------- 04/20/2014 19:44:27.215557 EDT | 04/20/2014 19:44:27.215557 EDT (1 row)
我错过了什么吗?
1)
These sql-standard functions all return values based on the start time
of the current transaction:
…
CURRENT_TIMESTAMP
…
2)
transaction_timestamp()
is equivalent toCURRENT_TIMESTAMP
,but is
named to clearly reflect what it returns.
3)
now()
is a traditional Postgresql equivalent totransaction_timestamp()
.
大胆强调我的.
所以,基本上,CURRENT_TIMESTAMP,transaction_timestamp()和now()完全相同. CURRENT_TIMESTAMP是一个函数的语法奇怪,没有尾对括号.这是根据sql标准.
如果未在sql语句中声明函数调用的列别名(需要一个),则别名默认为函数的名称.在内部,标准sql CURRENT_TIMESTAMP使用now()实现,并在您查看默认列别名时显示.
transaction_timestamp()执行相同的操作,但是这个是一个正确的Postgres函数,因此分配了默认的别名transaction_timestamp.
不要将这些函数中的任何一个与特殊的input constant 'now'
混淆.这只是特定日期/时间/时间戳值的几个符号缩写之一,quoting the manual:
… that will be converted to ordinary date/time values when read. (In particular,
now
and related strings are converted to a specific time value as soon as they are read.) All of these values need to be enclosed in single quotes when used as constants in sql commands.
它可能会增加混淆(当前 – 第10页)从这些特殊输入值中修剪任意数量的前导和尾随空格和括号({[()]}).因此’now()’:: timestamptz – 或者只是’now()’,其中不需要显式类型转换 – 也是有效的,并且恰好在大多数情况下评估与函数now()相同的时间戳.但这些是常量,通常不是你想要的列默认值.