Skip to content

Commit

Permalink
Fix a regression issue caused by typo in union modification (#417)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
forestkeeper authored Jul 25, 2024
1 parent 0749a9b commit 634e908
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/backend/parser/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -2345,8 +2345,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);
Expand Down
12 changes: 12 additions & 0 deletions src/test/regress/expected/prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ SELECT name, statement, parameter_types FROM pg_prepared_statements
| SELECT * FROM road WHERE thepath = $1; |
(5 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
Expand All @@ -187,3 +198,4 @@ SELECT name, statement, parameter_types FROM pg_prepared_statements
------+-----------+-----------------
(0 rows)

DROP table union_type;
15 changes: 15 additions & 0 deletions src/test/regress/sql/prepare.sql
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,22 @@ PREPARE q7(unknown) AS
SELECT name, statement, parameter_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;

0 comments on commit 634e908

Please sign in to comment.