release-22.2: sql: fix decimal evaluation edge cases #110298
Merged
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.
Backport 1/1 commits from #106472.
/cc @cockroachdb/release
Previously, the logic for decimal and float division, floor division and mod operators was incorrect for a few edge cases involving
NaN
orInfinity
values. For example,'NaN'::DECIMAL / 0
would throw a division-by-zero error when it should evaluate toNaN
and0/'inf'::DECIMAL
returned0E-2019
instead of just0
.This patch updates the special-case logic to mirror that of postgres, so division-by-zero errors always check the
NaN
case and the division by infinity case returns a0
without extra digits.Fixes #40929
Fixes #103633
Release note (bug fix): Fixed edge cases in decimal and float evaluation for division operators.
'NaN'::DECIMAL / 0
will now returnNaN
instead of a division-by-zero error, and0 / 'inf'::DECIMAL
will return0
instead of0E-2019
.Release justification: Fix for a decimal-precision edge case that is causing randomized test failures.