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
Division result exceeds numeric precision constraint #3731
Comments
It should be much safer to use numeric data types with sane precision and scale, 100000 is too large for normal use cases. The SQL Standard doesn't have any requirements for quotient's precision and scale, so database systems may choose any precision and scale for them. But I think that H2 can try to handle this corner case better, I'll take a look on it this week. |
Hi @katzyn,
I checked once again. We converted our database with migration script from version 1.4.199. Initially, the column had
Thank you. Please let me know if there is something I can do to help you. |
Due to this, H2 converts dividend to H2 determines that Here we may adjust both precision and scale to (We may not do the same for addition, subtraction, and multiplication, the SQL Standard requires a specific scale for them.) |
Column with count in its name usually should had ALTER TABLE TEST ALTER COLUMN COUNT SET DATA TYPE INTEGER; |
The problem
We use version 2.1.214, and it fails on the current master as well.
To reproduce the problem, please run this SQL script:
Last line will trigger following error:
I debugged the org.h2.expression.BinaryOperation#optimizeNumeric; it creates type info with precision and scale set to 100000. The produced result will stick to the defined scale, but it fails as the division result is bigger than one.
I see that performing additional rounding in org.h2.value.ValueNumeric#divide could help, but I wonder if it's in line with the desired behavior.
Please let me know if I can help you with the bug fix. I am eager to contribute.
I am unsure how relevant this might be, but PostgreSQL can deal with this script after changing the precision to the accepted maximum value of 1000.
Code
Code to reproduce the issue:
The text was updated successfully, but these errors were encountered: