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

Fixed case expression when one of the branch is NUMERIC and other is of EXACT NUMERIC. #3607

Conversation

Yvinayak07
Copy link
Contributor

Issues

CASE statement doesn't gives correct typmod when one of the branch is numeric and other is of exact numeric. The precision is being set 5 and scale is set to 4 in babelfish.
So expected result (123.0000) won't fit in Numeric(5,4). So we need to figure out correct precision and scale in this case.

SELECT CASE
WHEN 1 = 0 THEN 0.0001
ELSE 123
END;
Expected Result (TSQL): 123.0000
Actual Result (Babelfish): "Msg 33557097, Level 16, State 1, Line 2
numeric field overflow"
2)

Changes made to fix the issues

In the tsql_select_common_typmod hook, allowed exact numeric types for calculating correct precision and scale.

cherry-pick from #3584

Task: BABEL-5678
Authored-by: yashneet vinayak [email protected]
Signed-off-by: yashneet vinayak [email protected]

Test Scenarios Covered

  • **Use case based -**YES

  • **Boundary conditions -**YES

  • **Arbitrary inputs -**YES

  • **Negative test cases -**YES

  • Minor version upgrade tests -

  • Major version upgrade tests -

  • Performance tests -

  • Tooling impact -

  • **Client tests -**YES

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…of EXACT NUMERIC. (babelfish-for-postgresql#3584)

Earlier, CASE statement doesn't gives correct typmod when one of the branch is numeric and other is of exact numeric. The precision is being set 5 and scale is set to 4 in babelfish.
So expected result (123.0000) won't fit in Numeric(5,4). So we need to figure out correct precision and scale in this case.

To fix this in tsql_select_common_typmod hook, allowed exact numeric types for calculating correct precision and scale.

Task: BABEL-5678
Authored-by: yashneet vinayak [email protected]
Signed-off-by: yashneet vinayak [email protected]
@coveralls
Copy link
Collaborator

coveralls commented Mar 21, 2025

Pull Request Test Coverage Report for Build 13988568610

Details

  • 28 of 28 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 73.923%

Totals Coverage Status
Change from base Build 13970684913: 0.01%
Covered Lines: 43591
Relevant Lines: 58968

💛 - Coveralls

Signed-off-by: yashneet vinayak <[email protected]>
@KushaalShroff KushaalShroff merged commit 6217a44 into babelfish-for-postgresql:BABEL_3_X_DEV Mar 21, 2025
45 checks passed
@KushaalShroff KushaalShroff deleted the BABEL-5678-3_X branch March 21, 2025 16:32
fizzlr pushed a commit to amazon-aurora/babelfish_extensions that referenced this pull request Mar 24, 2025
…of EXACT NUMERIC. (babelfish-for-postgresql#3607)

Earlier, CASE statement doesn't gives correct typmod when one of the branch is numeric and other is of exact numeric. The precision is being set 5 and scale is set to 4 in babelfish.
So expected result (123.0000) won't fit in Numeric(5,4). So we need to figure out correct precision and scale in this case.

To fix this in tsql_select_common_typmod hook, allowed exact numeric types for calculating correct precision and scale.

Task: BABEL-5678
Authored-by: yashneet vinayak [email protected]
Signed-off-by: yashneet vinayak [email protected]
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.

3 participants