Make GREATEST and LEAST compliant with the SQL Standard #3862
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #3089.
GREATESTandLEASTare part of SQL:2023 Standard. Many database systems, including the H2, historically have these functions with various implementations, sometimes not fully compliant with the new Standard.A default implementation is changed to be fully compliant with the Standard.
An implementation for
Legacycompatibility mode is almost the same as it was in H2 historically¹, so it is possible to use this mode in applications if they need old behavior.Implementations for
PostgreSQLandMSSQLServercompatibility modes are also the same as they were before because these systems have the same incompatibility as H2.Implementations for all other compatibility modes are also standard-compliant.
Optional non-standard clauses are introduced to have a possibility to use both standard and historic implementations if they are needed. These clauses were suggested here:
https://modern-sql.com/caniuse/greatest-least#null
With
RESPECT NULLSstandard-compliant implementation will be used in any compatibility mode.With
IGNORE NULLSold-style implementation will be used in any compatibility mode.¹ There is also a difference in comparison operations with row values or array data types. These operations now use the same rules as regular comparison operations, earlier they incorrectly used rules of ordering operations.