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