问题描述
我想使用sysdate执行查询,例如:
I want to perform a query using sysdate like:
select up_time from exam where up_time like sysdate
这在Oracle中是可能的.
which is possible in Oracle.
但是,似乎PostgreSQL不支持sysdate.我在postgres文档中找不到sysdate. PostgreSQL中sysdate的替代品是什么?
However, it seems that PostgreSQL doesn't support sysdate. I couldn't find sysdate in postgres documentation. What is the replacement for sysdate in PostgreSQL?
推荐答案
SYSDATE
是仅Oracle的函数.
SYSDATE
is an Oracle only function.
Postgres支持ANSI标准的current_date
或current_timestamp
,并在手册中进行了记录:
http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
The ANSI standard defines current_date
or current_timestamp
which is supported by Postgres and documented in the manual:
http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT
(顺便说一句:Oracle也支持CURRENT_TIMESTAMP
)
(Btw: Oracle supports CURRENT_TIMESTAMP
as well)
您应注意current_timestamp
,statement_timestamp()
和clock_timestamp()
之间的区别(在手册中进行了说明,请参见上面的链接)
You should pay attention to the difference between current_timestamp
, statement_timestamp()
and clock_timestamp()
(which is explained in the manual, see the above link)
此声明:
完全没有任何意义.在Oracle和Postgres中都没有.如果要从今天"获取行,则需要类似以下内容的
Does not make any sense at all. Neither in Oracle nor in Postgres. If you want to get rows from "today", you need something like:
select up_time
from exam
where up_time = current_date
请注意,在Oracle中,您可能希望trunc(up_time) = trunc(sysdate)
摆脱Oracle中始终包含的时间部分.
Note that in Oracle you would probably want trunc(up_time) = trunc(sysdate)
to get rid of the time part that is always included in Oracle.
这篇关于PostgreSQL等同于Oracle的SYSDATE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!