applied when the select is a UNION (or other set-operation).
An alternative route to a fix would be to leave analyze.c alone and
change plan_set_operations in prepunion.c to take column names from
the topmost targetlist. But I am not sure that would work in all
cases. This patch seems the minimum-risk fix.
qry->isBinary = FALSE;
}
+ /*
+ * Any column names from CREATE TABLE AS need to be attached to both the
+ * top level and the leftmost subquery. We do not do this earlier
+ * because we do *not* want the targetnames list to be affected.
+ */
if (intoColNames)
+ {
applyColumnNames(qry->targetList, intoColNames);
+ applyColumnNames(leftmostQuery->targetList, intoColNames);
+ }
/*
* As a first step towards supporting sort clauses that are