Skip to content

H2Dialect.LimitClause produces invalid SQL instead of standard OFFSET / FETCH #1287

Closed
@katzyn

Description

@katzyn

H2 officially supports only OFFSET / FETCH from the SQL Standard:
https://h2database.com/html/commands.html#select
H2 accepts it unconditionally (even in compatibility modes for database systems without its support).

But H2Dialect produces non-standard LIMIT / OFFSET for a some reason:

public String getLimit(long limit) {
return "LIMIT " + limit;
}
@Override
public String getOffset(long offset) {
return "OFFSET " + offset;
}
@Override
public String getLimitOffset(long limit, long offset) {
return String.format("LIMIT %d OFFSET %d", limit, offset);
}

H2 accepts this legacy syntax only in Regular, Legacy, DB2, HSQLDB, MariaDB, MySQL, and PostgreSQL compatibility modes.
https://h2database.com/html/features.html#compatibility

It isn't accepted in Strict, Derby, MSSQLServer, and Oracle compatibility modes and it causes syntax errors like that one:
https://stackoverflow.com/questions/72880912/spring-boot-2-7-1-with-data-r2dbc-findbyid-fails-when-using-h2-with-mssqlserve

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions