2013-06-06 14 views
33

Voglio eseguire una query utilizzando sysdate come:Qual è l'equivalente PostgreSQL di SYSDATE da Oracle?

select up_time from exam where up_time like sysdate 

che è possibile in Oracle.

Tuttavia, sembra che PostgreSQL non supporti sysdate. Non sono riuscito a trovare sysdate nella documentazione di Postgres. Qual è la sostituzione di sysdate in PostgreSQL?

risposta

45

SYSDATE è una funzione solo Oracle.

Lo standard ANSI definisce current_date o current_timestamp che è supportato da Postgres e documentato nel manuale:
http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT

(Btw: Oracle supporta CURRENT_TIMESTAMP pure)

si dovrebbe prestare attenzione alla differenza tra current_timestamp, statement_timestamp() e clock_timestamp() (che è spiegato nel manuale, vedere il link sopra)


Questa dichiarazione:

select up_time from exam where up_time like sysdate

non fa alcun senso a tutti. Né in Oracle né in Postgres. Se si desidera ottenere le righe da "oggi", avete bisogno di qualcosa di simile:

select up_time 
from exam 
where up_time = current_date 

Si noti che in Oracle si sarebbe probabilmente vuole trunc(up_time) = trunc(sysdate) per sbarazzarsi della parte tempo che è sempre inclusa in Oracle.

Problemi correlati