From: Tom Lane Date: Thu, 13 Jun 2002 02:04:46 +0000 (+0000) Subject: Repair for bug #691 --- CREATE TABLE AS column aliases fail to be X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=78f6326d1c8c4825daa2a79273ee717086e70a11;p=users%2Fbernd%2Fpostgres.git Repair for bug #691 --- CREATE TABLE AS column aliases fail to be 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. --- diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index e9cd224ad1..287f986e8e 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -2212,8 +2212,16 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt) 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