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

Add hook in select_common_type for CHAR/NCHAR case #140

Conversation

wboettge
Copy link
Contributor

@wboettge wboettge commented May 9, 2023

Description

Currently, babelfish gives an error when UNION is used with fixed-length types of different lengths or null. This change fixes how types and typmods are handled within UNION and VALUES via two new hooks. It also prevents the early-coercion of UNKNOWNs to handle NULL and string literals.

Issues Resolved

BABEL-3348, BABEL-3392, BABEL-4157

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

@wboettge wboettge force-pushed the 3392-union-char-null branch from fd5cded to 41c178a Compare June 8, 2023 15:48
@wboettge wboettge force-pushed the 3392-union-char-null branch from 41c178a to 9f6d7be Compare August 7, 2023 19:45
With distinct, Postgres coerces the type of unknown-typed targets so it
may find an equality function. It selects TEXT as the type to coerce to.

The problem in T-SQL is if we are unioning the result of SELECT DISTINCT
NULL with a different type. Some types, BIT for example, do not have
conversion functions between TEXT. Therefore, SELECT CAST(1 as BIT)
UNION SELECT DISTINCT NULL fails unexpectantly in Babelfish.

This change coerces NULL values to INT4 instead of TEXT when using
Babelfish, fixing the result type and the union behavior.

Signed-off-by: Walt Boettge <[email protected]>
When unioning NCHAR with CHAR or NULL, the wrong output type is chosen.
This hook will cause select_common_type to to pick NCHAR as the result
type instead of CHAR in these cases.

Signed-off-by: Walt Boettge <[email protected]>
Signed-off-by: Walt Boettge <[email protected]>
@wboettge wboettge force-pushed the 3392-union-char-null branch from dfdfa5b to 77a5b98 Compare August 9, 2023 21:37
@wboettge wboettge marked this pull request as ready for review September 20, 2023 22:49
Copy link
Contributor

@forestkeeper forestkeeper left a comment

Choose a reason for hiding this comment

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

LGTM

@forestkeeper forestkeeper merged commit b327d84 into babelfish-for-postgresql:BABEL_3_X_DEV__PG_15_X Sep 25, 2023
Sairakan pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Nov 16, 2023
…tgresql#140)

* Fix SELECT DISTINCT NULL result type

With distinct, Postgres coerces the type of unknown-typed targets so it
may find an equality function. It selects TEXT as the type to coerce to.

The problem in T-SQL is if we are unioning the result of SELECT DISTINCT
NULL with a different type. Some types, BIT for example, do not have
conversion functions between TEXT. Therefore, SELECT CAST(1 as BIT)
UNION SELECT DISTINCT NULL fails unexpectantly in Babelfish.

This change coerces NULL values to INT4 instead of TEXT when using
Babelfish, fixing the result type and the union behavior.

Signed-off-by: Walt Boettge <[email protected]>
Task: BABEL-3348, BABEL-3392, BABEL-4157, BABEL-1874
priyansx pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Nov 22, 2023
…tgresql#140)

* Fix SELECT DISTINCT NULL result type

With distinct, Postgres coerces the type of unknown-typed targets so it
may find an equality function. It selects TEXT as the type to coerce to.

The problem in T-SQL is if we are unioning the result of SELECT DISTINCT
NULL with a different type. Some types, BIT for example, do not have
conversion functions between TEXT. Therefore, SELECT CAST(1 as BIT)
UNION SELECT DISTINCT NULL fails unexpectantly in Babelfish.

This change coerces NULL values to INT4 instead of TEXT when using
Babelfish, fixing the result type and the union behavior.

Signed-off-by: Walt Boettge <[email protected]>
Task: BABEL-3348, BABEL-3392, BABEL-4157, BABEL-1874
staticlibs pushed a commit to wiltondb/postgresql_modified_for_babelfish that referenced this pull request Jun 23, 2024
…tgresql#140)

* Fix SELECT DISTINCT NULL result type

With distinct, Postgres coerces the type of unknown-typed targets so it
may find an equality function. It selects TEXT as the type to coerce to.

The problem in T-SQL is if we are unioning the result of SELECT DISTINCT
NULL with a different type. Some types, BIT for example, do not have
conversion functions between TEXT. Therefore, SELECT CAST(1 as BIT)
UNION SELECT DISTINCT NULL fails unexpectantly in Babelfish.

This change coerces NULL values to INT4 instead of TEXT when using
Babelfish, fixing the result type and the union behavior.

Signed-off-by: Walt Boettge <[email protected]>
Task: BABEL-3348, BABEL-3392, BABEL-4157, BABEL-1874
forestkeeper pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Jul 24, 2024
Previously in the pr : babelfish-for-postgresql#140
We modified the union corece behavior of union select in babelfish, but
a typo wrongly changed the postgres behavior and caused a regression,
we'll fix the typo in this commit.

Signed-off-by: Zhibai Song <[email protected]>
Task: MANFRED-22834
forestkeeper added a commit that referenced this pull request Jul 25, 2024
* Fix a regression issue caused by typo in union modification

Previously in the pr : #140
We modified the union corece behavior of union select in babelfish, but
a typo wrongly changed the postgres behavior and caused a regression,
we'll fix the typo in this commit.

Signed-off-by: Zhibai Song <[email protected]>
Task: MANFRED-22834
forestkeeper added a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Jul 25, 2024
…h-for-postgresql#416)

* Fix a regression issue caused by typo in union modification

Previously in the pr : babelfish-for-postgresql#140
We modified the union corece behavior of union select in babelfish, but
a typo wrongly changed the postgres behavior and caused a regression,
we'll fix the typo in this commit.

Signed-off-by: Zhibai Song <[email protected]>
Task: MANFRED-22834
forestkeeper added a commit that referenced this pull request Jul 25, 2024
Previously in the pr : #140
We modified the union corece behavior of union select in babelfish, but
a typo wrongly changed the postgres behavior and caused a regression,
we'll fix the typo in this commit.

Task: MANFRED-22834
Signed-off-by: Zhibai Song <[email protected]>
staticlibs pushed a commit to wiltondb/postgresql_modified_for_babelfish that referenced this pull request Oct 8, 2024
…h-for-postgresql#417)


Previously in the pr : babelfish-for-postgresql#140
We modified the union corece behavior of union select in babelfish, but
a typo wrongly changed the postgres behavior and caused a regression,
we'll fix the typo in this commit.

Task: MANFRED-22834
Signed-off-by: Zhibai Song <[email protected]>
roshan0708 pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Oct 15, 2024
…abelfish-for-postgresql#416)

* Fix a regression issue caused by typo in union modification

Previously in the pr : babelfish-for-postgresql#140
We modified the union corece behavior of union select in babelfish, but
a typo wrongly changed the postgres behavior and caused a regression,
we'll fix the typo in this commit.

Signed-off-by: Zhibai Song <[email protected]>
Task: MANFRED-22834
shardgupta pushed a commit to amazon-aurora/postgresql_modified_for_babelfish that referenced this pull request Nov 8, 2024
…h-for-postgresql#416)

* Fix a regression issue caused by typo in union modification

Previously in the pr : babelfish-for-postgresql#140
We modified the union corece behavior of union select in babelfish, but
a typo wrongly changed the postgres behavior and caused a regression,
we'll fix the typo in this commit.

Signed-off-by: Zhibai Song <[email protected]>
Task: MANFRED-22834
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.

2 participants