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

Fix inconsistent formatting issue in convert function when converting from money to varchar #3360

Merged

Conversation

rohit01010
Copy link
Contributor

Description

Currently when converting from money to varchar using convert function with different style values, the result is inconsistent with the formatting. This PR will address this issue by updating the logic to handle these edge cases. The issues that will get addressed in this PR are as follows

  1. Extra space is getting added in the beginning of the result when style parameter is 0 or 2.
  2. When input is 0, then 0 is missing before decimal in the result for style 0 and 2. Also for style 1 the result has $ before decimal instead of 0. For example, when converting value 0 with money datatype to varchar datatype
    • For style 0, result is .00
    • For style 1, result is $.00
    • For style 2, result is .0000
  3. When style is 2, and the input has more than 2 digits after decimal, then the result is getting rounded upto 2 digits after decimal, which ideally should be rounded upto 4 digits.

Cherry-picked from: #3337

Authored-by: Rohit Bhagat [email protected]
Signed-off-by: Rohit Bhagat [email protected]

Issues Resolved

BABEL-5462

Test Scenarios Covered

  • Use case based - YES

  • Boundary conditions - YES

  • Arbitrary inputs - NA

  • Negative test cases - NA

  • Minor version upgrade tests - YES

  • Major version upgrade tests - YES

  • Performance tests - NA

  • Tooling impact - NA

  • 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.

… from money to varchar (babelfish-for-postgresql#3337)

Description
Currently when converting from money to varchar using convert function with different style values, the result is inconsistent with the formatting. This PR will address this issue by updating the logic to handle these edge cases. The issues that will get addressed in this PR are as follows

Extra space is getting added in the beginning of the result when style parameter is 0 or 2.
When input is 0, then 0 is missing before decimal in the result for style 0 and 2. Also for style 1 the result has $ before decimal instead of 0. For example, when converting value 0 with money datatype to varchar datatype
For style 0, result is  .00
For style 1, result is $.00
For style 2, result is  .0000
When style is 2, and the input has more than 2 digits after decimal, then the result is getting rounded upto 2 digits after decimal, which ideally should be rounded upto 4 digits.

Issues Resolved
BABEL-5462

Authored-by: Rohit Bhagat [email protected]
Signed-off-by: Rohit Bhagat [email protected]
@rohit01010 rohit01010 requested a review from Anikait143 January 6, 2025 10:52
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 12631185602

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.003%) to 74.876%

Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_tds/src/backend/tds/tdscomm.c 2 76.03%
Totals Coverage Status
Change from base Build 12596832761: -0.003%
Covered Lines: 46734
Relevant Lines: 62415

💛 - Coveralls

Copy link
Contributor

@jsudrik jsudrik left a comment

Choose a reason for hiding this comment

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

Approved.

@jsudrik jsudrik merged commit 414c7f2 into babelfish-for-postgresql:BABEL_4_X_DEV Jan 6, 2025
47 checks passed
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.

4 participants