diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 5f6640c4e87..88f3f9730cc 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -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); diff --git a/src/test/regress/expected/prepare.out b/src/test/regress/expected/prepare.out index 3306c696b17..47a7f325901 100644 --- a/src/test/regress/expected/prepare.out +++ b/src/test/regress/expected/prepare.out @@ -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 @@ -187,3 +198,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 985d0f05c96..006f12f7fb6 100644 --- a/src/test/regress/sql/prepare.sql +++ b/src/test/regress/sql/prepare.sql @@ -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; \ No newline at end of file