H2Dialect shouldn't use MySQL-style syntax and other potential problems
See original GitHub issue- All versions of H2 support
GENERATED BY DEFAULT AS IDENTITY
,GENERATED BY DEFAULT AS IDENTITY (START WITH 100)
, etc.
GENERATED ALWAYS AS IDENTITY
is accepted since H2 1.1.100 (2008-10-04), but its behavior was the same as BY DEFAULT
until H2 1.4.200, it is different only since H2 2.0.202.
There is a problem with H2Database.getAutoIncrementClause()
method, it returns MySQL compatibility syntax instead of standard one:
https://github.com/liquibase/liquibase/blob/6a609ce2cacb67d9a3aeda3f23e942752f935229/liquibase-core/src/main/java/liquibase/database/core/H2Database.java#L294
This legacy syntax is rejected since H2 2.0.202 in compatibility modes where it shouldn’t be used. In H2 2.0.204 it is available only in REGULAR
, LEGACY
, MARIADB
, and MYSQL
compatibility modes and is not available in STRICT
and all other modes.
Some people use these modes and Liquibase is unable to create identity columns, a syntax error is thrown: https://stackoverflow.com/questions/70453996/h2-version-2-0-202-auto-increment-not-working
-
Next value of a sequence should be fetched with standard
NEXT VALUE FOR sequenceName
expression, it is supported by all versions of H2: https://h2database.com/html/grammar.html#sequence_value_expression Liquibase seems to use buggy and deprecatedNEXTVAL()
function: https://h2database.com/html/functions.html#nextval https://github.com/liquibase/liquibase/blob/6a609ce2cacb67d9a3aeda3f23e942752f935229/liquibase-core/src/main/java/liquibase/database/core/H2Database.java#L164 This legacy function may not work in some compatibility modes or work in unexpected way, there are some deviations between compatibility modes. -
Current value of a sequence should be fetched with non-standard
CURRENT VALUE FOR sequnceName
in H2 1.4.200 and later versions: https://h2database.com/html/grammar.html#sequence_value_expression LegacyCURRVAL()
function should only be used in H2 1.4.199 and older versions, this function is also deprecated in H2 2.0: https://h2database.com/html/functions.html#currval https://github.com/liquibase/liquibase/blob/6a609ce2cacb67d9a3aeda3f23e942752f935229/liquibase-core/src/main/java/liquibase/database/core/H2Database.java#L165 This legacy function also may not work in some compatibility modes.
There are some other suspicious places.
-
getViewDefinition()
tries to findSELECT
in it, butSELECT …
in not the only one kind of queries, there are others, such as table value constructor (VALUES …
) and explicit table (TABLE tableName
). View definition may also start withWITH
-
getConcatSql()
usesCONCAT
function, why this is needed? Default implementation in superclass produces standard concatenation operator||
supported by all versions of H2. -
List of current datetime value functions contains various deprecated functions, but doesn’t contain standard functions for
TIMESTAMP [ WITHOUT TIME ZONE]
andTIME [WITHOUT TIME ZONE]
values: https://h2database.com/html/functions.html#localtimestamp https://h2database.com/html/functions.html#localtime
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
@DanielFran will do our best to take a look. Thanks.
Fixed by #3026