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

release-20.1: sql: fix casting of negative datums to decimals #48345

Merged
merged 1 commit into from
May 4, 2020

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented May 4, 2020

Backport 1/1 commits from #47483.

/cc @cockroachdb/release


Prior to this commit, when negative intervals, timestamps, and timestamptzs
were cast to decimals, the result was incorrect. The problem was due to the
fact that for these negative values, Decimal.Coeff.neg was being set to true,
while Decimal.Negative was false. As explained in the comment in decimal.go,
"Coeff must be positive. If it is negative results may be incorrect and apd
may panic."

This commit fixes the problem by setting Decimal.Negative to true and
Decimal.Coeff.neg to false when casting negative datums to decimals.

Fixes #47327

Release note (bug fix): Fixed incorrect results that could occur when
casting negative intervals or timestamps to type decimal.

Prior to this commit, when negative intervals, timestamps, and timestamptzs
were cast to decimals, the result was incorrect. The problem was due to the
fact that for these negative values, Decimal.Coeff.neg was being set to true,
while Decimal.Negative was false. As explained in the comment in decimal.go,
"Coeff must be positive. If it is negative results may be incorrect and apd
may panic."

This commit fixes the problem by setting Decimal.Negative to true and
Decimal.Coeff.neg to false when casting negative datums to decimals.

Fixes cockroachdb#47327

Release note (bug fix): Fixed incorrect results that could occur when
casting negative intervals or timestamps to type decimal.
@rytaft rytaft requested a review from yuzefovich May 4, 2020 15:02
@rytaft rytaft requested a review from a team as a code owner May 4, 2020 15:02
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

@rytaft rytaft merged commit 0583f97 into cockroachdb:release-20.1 May 4, 2020
@rytaft rytaft deleted the backport20.1-47483 branch May 4, 2020 15:52
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 this pull request may close these issues.

None yet

3 participants