Retain result type after UNION as base type in T-SQL (#487) #503
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.
Description
When a base type such as
money
is UNIONed with another integer type, the result type will befixeddecimal
instead ofmoney
, which is inconsistent with SQL Server's behaviour. And could also cause some characters not displaying well.Analysis
The root cause of the issue is Postgres will consider the base type of domain type as the result type. In Babelfish,
money
is implemented as a domain type offixeddecimal
. Actually,money
is a base type in T-SQL, thus Babelfish should retainmoney
type after UNION.Fix
After a final type has determined by the optimizer, check if it's a base type in T-SQL. If it is, try to use the domain type as result type if the domain type has higher precision than other types.
Task: BABEL-5242
Cherry-picked from https://github.com/amazon-aurora/postgresql_modified_for_babelfish/pull/new/babel_5242_dev15
By submitting this pull request, I confirm that my contribution is under the terms of the PostgreSQL license, 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.