Skip to content

Handling CASE expression when one branch is of decimal/numeric and other branch is of smallmoney/money. #3808

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

Merged

Conversation

tanyagupta17
Copy link
Contributor

@tanyagupta17 tanyagupta17 commented Jun 6, 2025

Description

Currently, we treat typmod for smallmoney/money datatype as default which leads to output differences in many cases.

Following are the fixes introduced in this PR :

  • Introduce typmod handling for smallmoney/money datatype for objects like table/procedure/views/functions/casts and handling their upgrade scenarios.
  • We are also handling p&s for declared variables, nested case expressions and unions having smallmoney/money as one of it's node.
  • It also takes case of round vs truncation behaviour around edge cases for fixeddecimal multiplication
  • Money/smallmoney and Numeric Arithmetic operations - precision and sclae correction and fixing TDS protocol Errors.
  • T_Param node handling for fixeddecimal dataypes (money and smallmoney) when numeric is another operand.
  • T_Aggref handling for Sum/Avg for fixeddecimal and other fixed length datatypes when numeric is another operand.
  • Handing typmod for smallmoney/money in pg catalogs for views metadata and during dump-restore.
  • Handling money/smallmoney typmod and fixeddecimal typmodin during dump-restore and by-passing typmod while deparsing for ISC check constraint.
  • Avoiding crashes and wrong results by updating sanity checks and setting intermittent result size appropirately for bigint and fixeddecimal multiplication.

Signed-off-by: Tanya Gupta [email protected]

Cherry-pick PR : #3719
Engine PR : babelfish-for-postgresql/postgresql_modified_for_babelfish#586

Issues Resolved

BABEL-5512, BABEL-5718, BABEL-5889, BABEL-5744, BABEL-5750, BABEL-5755, BABEL-5758, BABEL-5892, BABEL-5893, BABEL-5894, BABEL-5895, BABEL-5896, BABEL-5897, BABEL-5898

[List any issues this PR will resolve]

Test Scenarios Covered

  • Use case based - Yes

  • Boundary conditions - Yes

  • Arbitrary inputs - Yes

  • Negative test cases - Yes

  • Minor version upgrade tests - Yes

  • Major version upgrade tests - Yes

  • Performance tests - NA

  • Tooling impact - NA

  • Client tests - NA

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.

…her branch is of smallmoney/money. (babelfish-for-postgresql#3719)

Currently, we treat typmod for smallmoney/money datatype as default which leads to output differences in many cases.

Following are the fixes introduced in this PR :

Introduce typmod handling for smallmoney/money datatype for objects like table/procedure/views/functions/casts and handling their upgrade scenarios.
We are also handling p&s for declared variables, nested case expressions and unions having smallmoney/money as one of it's node.
It also takes case of round vs truncation behaviour around edge cases for fixeddecimal multiplication
Money/smallmoney and Numeric Arithmetic operations - precision and sclae correction and fixing TDS protocol Errors.
T_Param node handling for fixeddecimal dataypes (money and smallmoney) when numeric is another operand.
T_Aggref handling for Sum/Avg for fixeddecimal and other fixed length datatypes when numeric is another operand.
Handing typmod for smallmoney/money in pg catalogs for views metadata and during dump-restore.
Handling money/smallmoney typmod and fixeddecimal typmodin during dump-restore and by-passing typmod while deparsing for ISC check constraint.
Avoiding crashes and wrong results by updating sanity checks and setting intermittent result size appropirately for bigint and fixeddecimal multiplication.
Signed-off-by: Tanya Gupta [email protected]

Engine PR : babelfish-for-postgresql/postgresql_modified_for_babelfish#575
@coveralls
Copy link
Collaborator

coveralls commented Jun 6, 2025

Pull Request Test Coverage Report for Build 15483756743

Details

  • 71 of 84 (84.52%) changed or added relevant lines in 6 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.05%) to 75.357%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contrib/babelfishpg_money/fixeddecimal.c 8 14 57.14%
contrib/babelfishpg_tsql/src/hooks.c 12 19 63.16%
Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_money/fixeddecimal.c 1 72.57%
contrib/babelfishpg_tsql/src/hooks.c 1 84.93%
Totals Coverage Status
Change from base Build 15437394665: 0.05%
Covered Lines: 48562
Relevant Lines: 64443

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

Identical changes to merge done for 5_x. Approved.

@jsudrik jsudrik merged commit 1fa4135 into babelfish-for-postgresql:BABEL_4_X_DEV Jun 6, 2025
48 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