Skip to content

Commit

Permalink
Fix a regression issue caused by typo in union modification (babelfis…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
forestkeeper authored and shardgupta committed Nov 8, 2024
1 parent 8fc5779 commit c275f49
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 @@ -2355,8 +2355,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 @@ -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
Expand All @@ -192,3 +203,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 @@ -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;

0 comments on commit c275f49

Please sign in to comment.