1

I am trying to execute this SQL query

SELECT * FROM GY.TABLE_NAME WHERE TEST_ID < 999999999 AND current_timestamp > TEST_GMTS + 20 HOURS

When I am expecting it, the response is

SQL error 42000, sql state : 42000 Syntax error in SQL statement "SELECT * FROM GY.TABLE_NAME WHERE TEST_ID < 999999999 AND current_timestamp > TEST_GMTS + 20 HOURS[*]"

Org.hiberante.exception.sqlgrammerexception: could not prepare statement

1 Answers1

1

For H2 (and for any other DBMS that supports standard INTERVAL data type) you need to use

SELECT * FROM GY.TABLE_NAME WHERE TEST_ID < 999999999
    AND CURRENT_TIMESTAMP > TEST_GMTS + INTERVAL '20' HOUR;

Unfortunately, it looks like this standard-compliant syntax isn't supported by DB2.

20 HOURS is DB2-specific.

It means you need to use different SQL for different databases.


The next version of H2 (2.0.*) will also support more exotic syntax

SELECT * FROM GY.TABLE_NAME WHERE TEST_ID < 999999999
    AND CURRENT_TIMESTAMP > TEST_GMTS + 20 HOUR;

(with HOUR only, HOURS are invalid). This syntax is accepted by DB2 too, so hypothetically you can compile H2 from its current sources and use this own build instead of released version if you really need to use the same SQL for both H2 and DB2, but current H2 is very different from 1.4.* and you may run into some other issue.

Evgenij Ryazanov
  • 6,960
  • 2
  • 10
  • 18