@@ -56,7 +56,6 @@ static Node *transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
5656 bool isTopLevel , List * * targetlist );
5757static void determineRecursiveColTypes (ParseState * pstate ,
5858 Node * larg , List * nrtargetlist );
59- static void applyColumnNames (List * dst , List * src );
6059static Query * transformUpdateStmt (ParseState * pstate , UpdateStmt * stmt );
6160static List * transformReturningList (ParseState * pstate , List * returningList );
6261static Query * transformDeclareCursorStmt (ParseState * pstate ,
@@ -964,13 +963,8 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
964963 pstate -> p_windowdefs ,
965964 & qry -> targetList );
966965
967- /* handle any SELECT INTO/CREATE TABLE AS spec */
968- if (stmt -> intoClause )
969- {
970- qry -> intoClause = stmt -> intoClause ;
971- if (stmt -> intoClause -> colNames )
972- applyColumnNames (qry -> targetList , stmt -> intoClause -> colNames );
973- }
966+ /* SELECT INTO/CREATE TABLE AS spec is just passed through */
967+ qry -> intoClause = stmt -> intoClause ;
974968
975969 qry -> rtable = pstate -> p_rtable ;
976970 qry -> jointree = makeFromExpr (pstate -> p_joinlist , qual );
@@ -1191,13 +1185,8 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
11911185 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
11921186 errmsg ("SELECT FOR UPDATE/SHARE cannot be applied to VALUES" )));
11931187
1194- /* handle any CREATE TABLE AS spec */
1195- if (stmt -> intoClause )
1196- {
1197- qry -> intoClause = stmt -> intoClause ;
1198- if (stmt -> intoClause -> colNames )
1199- applyColumnNames (qry -> targetList , stmt -> intoClause -> colNames );
1200- }
1188+ /* CREATE TABLE AS spec is just passed through */
1189+ qry -> intoClause = stmt -> intoClause ;
12011190
12021191 /*
12031192 * There mustn't have been any table references in the expressions, else
@@ -1268,7 +1257,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
12681257 int leftmostRTI ;
12691258 Query * leftmostQuery ;
12701259 SetOperationStmt * sostmt ;
1271- List * intoColNames = NIL ;
12721260 List * sortClause ;
12731261 Node * limitOffset ;
12741262 Node * limitCount ;
@@ -1306,11 +1294,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
13061294 leftmostSelect = leftmostSelect -> larg ;
13071295 Assert (leftmostSelect && IsA (leftmostSelect , SelectStmt ) &&
13081296 leftmostSelect -> larg == NULL );
1309- if (leftmostSelect -> intoClause )
1310- {
1311- qry -> intoClause = leftmostSelect -> intoClause ;
1312- intoColNames = leftmostSelect -> intoClause -> colNames ;
1313- }
1297+ qry -> intoClause = leftmostSelect -> intoClause ;
13141298
13151299 /* clear this to prevent complaints in transformSetOperationTree() */
13161300 leftmostSelect -> intoClause = NULL ;
@@ -1460,19 +1444,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
14601444 qry -> limitCount = transformLimitClause (pstate , limitCount ,
14611445 "LIMIT" );
14621446
1463- /*
1464- * Handle SELECT INTO/CREATE TABLE AS.
1465- *
1466- * Any column names from CREATE TABLE AS need to be attached to both the
1467- * top level and the leftmost subquery. We do not do this earlier because
1468- * we do *not* want sortClause processing to be affected.
1469- */
1470- if (intoColNames )
1471- {
1472- applyColumnNames (qry -> targetList , intoColNames );
1473- applyColumnNames (leftmostQuery -> targetList , intoColNames );
1474- }
1475-
14761447 qry -> rtable = pstate -> p_rtable ;
14771448 qry -> jointree = makeFromExpr (pstate -> p_joinlist , NULL );
14781449
@@ -1892,44 +1863,6 @@ determineRecursiveColTypes(ParseState *pstate, Node *larg, List *nrtargetlist)
18921863 analyzeCTETargetList (pstate , pstate -> p_parent_cte , targetList );
18931864}
18941865
1895- /*
1896- * Attach column names from a ColumnDef list to a TargetEntry list
1897- * (for CREATE TABLE AS)
1898- */
1899- static void
1900- applyColumnNames (List * dst , List * src )
1901- {
1902- ListCell * dst_item ;
1903- ListCell * src_item ;
1904-
1905- src_item = list_head (src );
1906-
1907- foreach (dst_item , dst )
1908- {
1909- TargetEntry * d = (TargetEntry * ) lfirst (dst_item );
1910- ColumnDef * s ;
1911-
1912- /* junk targets don't count */
1913- if (d -> resjunk )
1914- continue ;
1915-
1916- /* fewer ColumnDefs than target entries is OK */
1917- if (src_item == NULL )
1918- break ;
1919-
1920- s = (ColumnDef * ) lfirst (src_item );
1921- src_item = lnext (src_item );
1922-
1923- d -> resname = pstrdup (s -> colname );
1924- }
1925-
1926- /* more ColumnDefs than target entries is not OK */
1927- if (src_item != NULL )
1928- ereport (ERROR ,
1929- (errcode (ERRCODE_SYNTAX_ERROR ),
1930- errmsg ("CREATE TABLE AS specifies too many column names" )));
1931- }
1932-
19331866
19341867/*
19351868 * transformUpdateStmt -
0 commit comments