Add Interval to date in HSQLDB based on other colu

2019-09-10 02:59发布

问题:

I'm using hsqldb as in-memory database for unittests, the production system is running with mysql. The following query does work with mysql, but not if applied with hsqldb:

select * from table where columnTimestamp + INTERVAL 'columnDays' DAY < now();

I want to retrieve all specific rows where the interval is based on another column. When I use fixed values it does work with hsqldb, but this is not the required behaviour.

The errormessage hsqldb returns:

data exception: invalid interval format / Error Code: -3406 / State: 22006

回答1:

Multiply a constant interval with your column.

select * 
from table 
where columnTimestamp + (INTERVAL '1' DAY * columndays) < now();


标签: sql hsqldb