How can I set sysdate in H2? (for testing)

2,015 views
Skip to first unread message

Kirill

unread,
Aug 18, 2018, 10:40:50 AM8/18/18
to H2 Database

I use H2 for testing and I want to set sysdate.

I tried to create an alias for sysdate to my own implementation, but then I couldn't use it with arithmetic like sysdate - ?. There was exception: Unknown data type: "?"

I tried to replace sysdate string to smth like timestamp '2018-01-01 11:11:11.123' or parsedatetime('2018-01-01 11:11:11.123', 'yyyy-MM-dd hh:mm:ss.SSS') in runtime. There was same exception, like in previous attempt.

Yes, I can add cast(? as number) to all my sql, but it isn't a good solution for me.

Do you have any idea, how can I do this?

ps: I also use Spring. Maybe it will help

Christian MICHON

unread,
Aug 19, 2018, 4:06:01 AM8/19/18
to H2 Database
Please share the alias you wrote and how you invoked it.

Christian

Evgenij Ryazanov

unread,
Aug 19, 2018, 5:44:15 AM8/19/18
to H2 Database
It does not matter, neither built-in date-time function nor alias for date-time function nor other date-time value cannot be used together with parameter in subtraction operation in H2. This is a known limitation.

To use such arithmetic operation parameter should be wrapped in CAST operator or in CONVERT() function if compatibility with some other database that don't have CAST operator is required.

Similar issue was recently reported on GitHub:
Reply all
Reply to author
Forward
0 new messages