From 5adef0f64dc661c0cf89c5e876cebaee4e532323 Mon Sep 17 00:00:00 2001 From: Zhibai Song Date: Thu, 25 Jul 2024 10:23:04 -0700 Subject: [PATCH] BABEL: Fix a regression issue caused by typo in union modification (#416) * Fix a regression issue caused by typo in union modification Previously in the pr : https://github.com/babelfish-for-postgresql/postgresql_modified_for_babelfish/pull/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 Task: MANFRED-22834 --- src/backend/parser/analyze.c | 4 ++-- src/test/regress/expected/prepare.out | 12 ++++++++++++ src/test/regress/sql/prepare.sql | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 04445166bf3..7d4cd4aa2c7 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -2306,8 +2306,8 @@ transformSetOperationTree(ParseState *pstate, SelectStmt *stmt, if (rcoltype != UNKNOWNOID) rcolnode = coerce_to_common_type(pstate, rcolnode, rescoltype, context); - else if ((IsA(lcolnode, Const) || - IsA(lcolnode, Param)) && sql_dialect != SQL_DIALECT_TSQL) + else if ((IsA(rcolnode, Const) || + IsA(rcolnode, Param)) && sql_dialect != SQL_DIALECT_TSQL) { rcolnode = coerce_to_common_type(pstate, rcolnode, rescoltype, context); diff --git a/src/test/regress/expected/prepare.out b/src/test/regress/expected/prepare.out index 5815e17b39c..9ba7ffc74fc 100644 --- a/src/test/regress/expected/prepare.out +++ b/src/test/regress/expected/prepare.out @@ -184,6 +184,17 @@ SELECT name, statement, parameter_types, result_types FROM pg_prepared_statement | UPDATE tenk1 SET stringu1 = $2 WHERE unique1 = $1; | | (6 rows) +CREATE TABLE union_type (id int primary key, name varchar(20)); +PREPARE q9 +AS +WITH temp1 AS ( + SELECT * from union_type + UNION + SELECT + $1 AS id, + $2 AS name +) +SELECT * from temp1; -- test DEALLOCATE ALL; DEALLOCATE ALL; SELECT name, statement, parameter_types FROM pg_prepared_statements @@ -192,3 +203,4 @@ SELECT name, statement, parameter_types FROM pg_prepared_statements ------+-----------+----------------- (0 rows) +DROP table union_type; diff --git a/src/test/regress/sql/prepare.sql b/src/test/regress/sql/prepare.sql index c6098dc95ce..6d57a8e9266 100644 --- a/src/test/regress/sql/prepare.sql +++ b/src/test/regress/sql/prepare.sql @@ -78,7 +78,22 @@ PREPARE q8 AS SELECT name, statement, parameter_types, result_types FROM pg_prepared_statements ORDER BY name; +CREATE TABLE union_type (id int primary key, name varchar(20)); + +PREPARE q9 +AS +WITH temp1 AS ( + SELECT * from union_type + UNION + SELECT + $1 AS id, + $2 AS name +) +SELECT * from temp1; + -- test DEALLOCATE ALL; DEALLOCATE ALL; SELECT name, statement, parameter_types FROM pg_prepared_statements ORDER BY name; + +DROP table union_type; \ No newline at end of file