akarshan2701 / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

mysql compatiblity function UNIX_TIMESTAMP #211

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
hi!

although the function can be user-defined as:

CREATE ALIAS UNIX_TIMESTAMP AS $$ long unix_timestamp() { return 
System.currentTimeMillis()/1000L; } $$;

myself thinks that it should be part of the standard function set because i 
couldn't find another function returning the unixtime or am i missing something.

cheers,

Original issue reported on code.google.com by teref...@gmail.com on 24 Jun 2010 at 12:47

GoogleCodeExporter commented 8 years ago
Hi,

Do you know if other databases support this or a similar function?

Regards,
Thomas

Original comment by thomas.t...@gmail.com on 25 Jun 2010 at 4:19

GoogleCodeExporter commented 8 years ago
in Postgrssql there is: EXTRACT('epoch' FROM ...)

Oracle does not have unixtime but this: 
http://www.techonthenet.com/oracle/functions/to_timestamp.php

not in M$Sql but this: 
http://www.bigresource.com/MS_SQL-UNIX-Time-Conversion-Functions-8h91OTq4.html

Sybase is similar to M$Sql.

I've not looked upon the source yet but would you accept patches for additional 
functions ?

Original comment by teref...@gmail.com on 1 Jul 2010 at 10:36

GoogleCodeExporter commented 8 years ago
Hi,

This also works: 
call datediff(second, '1970-01-01', now());

It returns the same value as:
CREATE ALIAS UNIX_TIMESTAMP AS $$ long unix_timestamp() { return 
System.currentTimeMillis()/1000L; } $$;
call UNIX_TIMESTAMP();

> would you accept patches for additional functions ?

Yes, please. You can submit them in the same form as above (as a SQL 
statement). I would like to not add such compatibility features as 'built-in' 
functions (like CAST). Instead, I would like to keep 'compatibility' functions 
separate from the main database. My idea is to keep such functions / features 
in a separate 'module' so that the main database engine stays small. However, 
so far, there is no such module system. For example, the UNIX_TIMESTAMP is 
already included within H2, but in a separate file:

http://code.google.com/p/h2database/source/browse/trunk/h2/src/tools/org/h2/mode
/FunctionsMySQL.java

If you want, you can submit patches for this file, or for other such files 
(FunctionPostgreSQL.java and so on).

I really need to work on modularization, so those functions are automatically 
included when switching the mode (MODE=MYSQL in your case). I will add a 
feature request. I think that has relatively high priority.

Original comment by thomas.t...@gmail.com on 2 Jul 2010 at 3:12

GoogleCodeExporter commented 8 years ago
This issue is in the roadmap at http://www.h2database.com/html/roadmap.html - 
priority is tracked there.

Original comment by thomas.t...@gmail.com on 28 Jan 2011 at 7:37

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi,
I am trying to create the same alias as written in this line from Java -

CREATE ALIAS UTC_TIMESTAMP AS $$ long utc_timestamp(){return 
System.currentTimeMillis(); } $$;

But I am getting an syntax error in my SQL statement which on debugging I found 
that the SQL statement after the first semicolon( } $$;) is ignored. The first 
semicolon is used to terminate the return statement. 

What can I do so that the SQL statement after the first semicolon is not 
ignored? 

PS: I am able to create alias on H2 console using the same line. Error is only 
when I am trying to create this from Java.

Original comment by navunive...@gmail.com on 8 Jun 2015 at 10:05

GoogleCodeExporter commented 8 years ago
Hi,

Please don't use the issue tracking for questions. Use the Google Group, or 
Stackoverflow, as described.

Regards,
Thomas

Original comment by thomas.t...@gmail.com on 9 Jun 2015 at 6:29