Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GREATEST and LEAST aren't fully compliant with the SQL Standard #3089

Closed
gabrielsky opened this issue Apr 14, 2021 · 3 comments · Fixed by #3862
Closed

GREATEST and LEAST aren't fully compliant with the SQL Standard #3089

gabrielsky opened this issue Apr 14, 2021 · 3 comments · Fixed by #3862

Comments

@gabrielsky
Copy link

gabrielsky commented Apr 14, 2021

the function "least()" have diffent behavior
myqsl : If any argument is NULL, the result is NULL. No comparison is needed.
h2 : all value must be null return null

example:
least(null,123)
in mysql return null,but h2 return 123

we use h2 as junit test db,so hope they have same behavior

h2 version:1.4.200

@katzyn
Copy link
Contributor

katzyn commented Apr 14, 2021

This function is vendor-specific, its implementations are different in Oracle, MySQL, and H2.

Standard-compliant CASE WHEN A < B OR A IS NULL THEN A ELSE B END should return the same results in all these DBMS.

@katzyn
Copy link
Contributor

katzyn commented Apr 14, 2021

I don't know where this function came from and why it is implemented in that way in H2. It looks like something very useful when there are more than two arguments, but its behavior in presence of NULL values looks strange, but this behavior is documented.

Some functions have optional clauses, for example LEAD and LAG have RESPECT NULLS and IGNORE NULLS; JSON functions have NULL ON NULL and ABSENT ON NULL. Maybe non-standard LEAST and GREATEST need some clauses like these, with default that depends on compatibility mode.

@gabrielsky
Copy link
Author

gabrielsky commented Apr 15, 2021

@katzyn thanks for reply , I'll pay attention to test diffent database non-standard function behavior before use it

This function is vendor-specific, its implementations are different in Oracle, MySQL, and H2.

Standard-compliant CASE WHEN A < B OR A IS NULL THEN A ELSE B END should return the same results in all these DBMS.

I don't know where this function came from and why it is implemented in that way in H2. It looks like something very useful when there are more than two arguments, but its behavior in presence of NULL values looks strange, but this behavior is documented.

Some functions have optional clauses, for example LEAD and LAG have RESPECT NULLS and IGNORE NULLS; JSON functions have NULL ON NULL and ABSENT ON NULL. Maybe non-standard LEAST and GREATEST need some clauses like these, with default that depends on compatibility mode.

@katzyn katzyn changed the title the function"least" is diffent from mysql GREATEST and LEAST aren't fully compliant with the SQL Standard Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants