Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 718
kir55rus Avatar asked Nov 18 '22 04:11

kir55rus


1 Answers

If you use two databases at once, you should avoid usage of vendor-specific syntax.

You can use SQL Standard-compliant

LOCALTIMESTAMP - INTERVAL '30' MINUTE

in recent versions of Oracle and H2.

I already had this problem and that was the solution it worked.

like image 180
Jonathan Ferreira Avatar answered Dec 05 '22 11:12

Jonathan Ferreira