Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is PostgreSQL equivalent of SYSDATE from Oracle?

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, it seems that PostgreSQL doesn't support sysdate. I couldn't find sysdate in postgres documentation. What is the replacement for sysdate in PostgreSQL?

like image 230
user2365917 Avatar asked Jun 06 '13 11:06

user2365917


People also ask

Does Postgres have Sysdate?

However, it seems that PostgreSQL doesn't support sysdate.

What type is Sysdate in Oracle?

SYSDATE returns the current date and time set for the operating system on which the database server resides. The data type of the returned value is DATE , and the format returned depends on the value of the NLS_DATE_FORMAT initialization parameter. The function requires no arguments.

How do I get the current time in PostgreSQL?

Postgresql now() The NOW() function in Postgresql is used to get the current date and time. The return type of the NOW() function is the timestamp with the time zone. We can fetch the current date and time by using the PostgreSQL NOW() function. This function has a return type i.e. the timestamp with the time zone.


2 Answers

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)


The part 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.

like image 68
a_horse_with_no_name Avatar answered Sep 20 '22 09:09

a_horse_with_no_name


NOW() is the replacement of Oracle Sysdate in Postgres.

Try "Select now()", it will give you the system timestamp.

like image 31
Virendra Patel Avatar answered Sep 20 '22 09:09

Virendra Patel