Revisiting manipulating CURRENT_TIMESTAMP

Skip to first unread message


Jul 21, 2022, 9:24:28 AM7/21/22
to H2 Database
In a previous post which a later closed as solved I had a side question that I would like answered:

Is there a way to tell H2 to resolve CURRENT_TIMESTAMP to some specific value when doing insert/merge/update statements with columns that default to CURRENT_TIMESTAMP or are set to CURRENT_TIMESTAMP on update?

I would like to change that value for each statement while redoing application level database logging.

Kind regards,


Evgenij Ryazanov

Jul 21, 2022, 9:56:26 AM7/21/22
to H2 Database

You can only add ;BUILTIN_ALIAS_OVERRIDE=TRUE to JDBC URL and create an own user-defined function with that name (CREATE ALIAS "CURRENT_TIMESTAMP" …):

But usually it is better to move that logic from database level to Java persistence level or application level.


Jul 28, 2022, 6:59:39 AM7/28/22
to H2 Database
Sorry for the late response, I was down with Covid.

That makes sense, thanks! I would have to look into user defined functions but as long as they can make use of connection-specific state (the normal CURRENT_TIMESTAMP would have to be used simultaneously on all connections except the one performing the redo) this should work nicely.

I agree that this should be handled in the application layer but I have quite some legacy code that lacks the abstraction layers of the current code base that allows me to handle this there. This trick can help me add transparent log/redo functionality to the older parts of our application.

Reply all
Reply to author
0 new messages