What is PostgreSQL equivalent of SYSDATE from Oracle?

前端 未结 4 986
梦如初夏
梦如初夏 2021-02-04 23:01

I want to perform a query using sysdate like:

select up_time from exam where up_time like sysdate

which is possible in Oracle.

However,

4条回答
  •  执笔经年
    2021-02-04 23:56

    SYSDATE is an Oracle only function.

    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

    (Btw: Oracle supports CURRENT_TIMESTAMP as well)

    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)


    This statement:

    select up_time from exam where up_time like sysdate

    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
    

    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.

提交回复
热议问题