Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to get datetime for every database

My friend asking me if there a way to use 1 query to select datetime and use it for any database.

Atm he using this query for Oracle :

SELECT vt_sysdate() FROM dual;

I know dual table is for Oracle only. But he want to use this same query for other database, for example PostgreSQL, as well.

So is there a way to make this query run on every database (Maybe by create a dual table for every database). Or is there a query to get system datetime that work on any database ?

Thank you for you help.

like image 787
mameo Avatar asked Mar 26 '26 13:03

mameo


1 Answers

No, I don't think so, because Oracle insists on being weird, and MS SQL doesn't seem to support the standard current_date at all.

MySQL accepts SELECT current_date;, doesn't understand VALUES.

PostgreSQL accepts SELECT current_date; or VALUES.

MS SQL doesn't seem to understand current_date at all.

Oracle understands current_date but not scalar queries without FROM.

like image 145
Craig Ringer Avatar answered Mar 29 '26 03:03

Craig Ringer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!