How can I form a SQL Query for a HSQLDB that counts the # of rows per day using a BIGINT type for a date?

被刻印的时光 ゝ 提交于 2019-12-01 14:22:59

The simple answer is HSQLDB 1.8 is an old version and does not support some advanced functions. HSQLDB 2.3.x supports a full range of functions to convert between different representations.

With HSQLDB 1.8 it is possible to create your own function in Java to convert the millisecond value of a Timestamp to a java.sql.Timestamp or java.sql.Date

Something like this in a class that you create:

static java.sql.Date millisToDate(long millis) {
    return new java.sql.Date(millis);
}

If you then include this class on the classpath used for running the database, you can call the function in your SELECT statement like this:

SELECT ENTRYID, "myclass.millisToDate"(REVOCATIONDATE) FROM ENTRY

Your result example will look like this:

SELECT MIN(ENTRYID), COUNT(ENTRYID), "myclass.millisToDate"(REVOCATIONDATE) FROM ENTRY
    GROUP BY "myclass.millisToDate"(REVOCATIONDATE)

I haven't actually tried any of the above suggestions, but they should work, perhaps with some alteration.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!