Skip to content

SYSDATE behavior changed in 2.x #3387

@nicholas-s-perkins

Description

@nicholas-s-perkins

Hello H2 folks.

When upgrading from H2 1.4.200 to 2.0.202 (also to latest 2.1.210), I noticed that what SYSDATE returns has changed and it no longer includes time information.

Details

For context I use H2 to build query tests for an app that uses an Oracle database and run H2 with MODE=Oracle.

These are the results I get from selecting sysdate and current_date from H2 1.x and 2.x:

-- H2 1.x
sysdate= 2022-01-20 12:33:37.966253
current_date= 2022-01-20 00:00:00.0
-- H2 2.x
sysdate= 2022-01-20 00:00:00.0
current_date= 2022-01-20 00:00:00.0

This is an issue for us since Oracle SYSDATE includes time information to second precision (also seems to be true of SYSDATE() in mysql). I couldn't find a reason for this change in the release notes.

While I'm uncertain as to why this would be a desirable change, looking through docs it did seem like there was maybe a way for me to change the behavior by using my own alias override. Except that also does not appear to work.

-- where Sysdate.sysdate just returns a timestamp with second precision
SET BUILTIN_ALIAS_OVERRIDE TRUE;
CREATE ALIAS CURRENT_DATE FOR "com.nsperkins.h2test.util.h2.Sysdate.sysdate";
CREATE ALIAS SYSDATE FOR "com.nsperkins.h2test.util.h2.Sysdate.sysdate";
sysdate= 2022-01-20 00:00:00.0
current_date= 2022-01-20 12:37:49.0

Interestingly enough the alias override for current_date did work, but the alias for sysdate appears to be ignored.

Questions

  1. Was the SYSDATE behavior change intentional?
  2. If the change was intentional, could MODE=Oracle have the more oracle-y SYSDATE behavior? For what it's worth current_date and sysdate both return time with second precision in Oracle but they have different timezone behavior.
  3. Is it a bug that CREATE ALIAS SYSDATE... does not appear to have any effect?
  4. Is there maybe some other workaround I could do? I combed through the docs but did not see anything obvious.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions