question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

H2Dialect shouldn't use MySQL-style syntax and other potential problems

See original GitHub issue
  1. 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

  1. 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 deprecated NEXTVAL() 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.

  2. 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 Legacy CURRVAL() 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.

  1. getViewDefinition() tries to find SELECT in it, but SELECT … 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 with WITH

  2. getConcatSql() uses CONCAT function, why this is needed? Default implementation in superclass produces standard concatenation operator || supported by all versions of H2.

  3. List of current datetime value functions contains various deprecated functions, but doesn’t contain standard functions for TIMESTAMP [ WITHOUT TIME ZONE] and TIME [WITHOUT TIME ZONE] values: https://h2database.com/html/functions.html#localtimestamp https://h2database.com/html/functions.html#localtime

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kataggartcommented, Jul 28, 2022

@DanielFran will do our best to take a look. Thanks.

0reactions
nvoxlandcommented, Aug 1, 2022

Fixed by #3026

Read more comments on GitHub >

github_iconTop Results From Across the Web

Features - H2 Database Engine
Features. Feature List H2 in Use Connection Modes Database URL Overview Connecting to an Embedded (Local) Database In-Memory Databases Database ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found