@@ -56,7 +56,6 @@ static Node *transformSetOperationTree(ParseState *pstate, SelectStmt *stmt,
56
56
bool isTopLevel , List * * targetlist );
57
57
static void determineRecursiveColTypes (ParseState * pstate ,
58
58
Node * larg , List * nrtargetlist );
59
- static void applyColumnNames (List * dst , List * src );
60
59
static Query * transformUpdateStmt (ParseState * pstate , UpdateStmt * stmt );
61
60
static List * transformReturningList (ParseState * pstate , List * returningList );
62
61
static Query * transformDeclareCursorStmt (ParseState * pstate ,
@@ -964,13 +963,8 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
964
963
pstate -> p_windowdefs ,
965
964
& qry -> targetList );
966
965
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 ;
974
968
975
969
qry -> rtable = pstate -> p_rtable ;
976
970
qry -> jointree = makeFromExpr (pstate -> p_joinlist , qual );
@@ -1191,13 +1185,8 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
1191
1185
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
1192
1186
errmsg ("SELECT FOR UPDATE/SHARE cannot be applied to VALUES" )));
1193
1187
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 ;
1201
1190
1202
1191
/*
1203
1192
* There mustn't have been any table references in the expressions, else
@@ -1268,7 +1257,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
1268
1257
int leftmostRTI ;
1269
1258
Query * leftmostQuery ;
1270
1259
SetOperationStmt * sostmt ;
1271
- List * intoColNames = NIL ;
1272
1260
List * sortClause ;
1273
1261
Node * limitOffset ;
1274
1262
Node * limitCount ;
@@ -1306,11 +1294,7 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
1306
1294
leftmostSelect = leftmostSelect -> larg ;
1307
1295
Assert (leftmostSelect && IsA (leftmostSelect , SelectStmt ) &&
1308
1296
leftmostSelect -> larg == NULL );
1309
- if (leftmostSelect -> intoClause )
1310
- {
1311
- qry -> intoClause = leftmostSelect -> intoClause ;
1312
- intoColNames = leftmostSelect -> intoClause -> colNames ;
1313
- }
1297
+ qry -> intoClause = leftmostSelect -> intoClause ;
1314
1298
1315
1299
/* clear this to prevent complaints in transformSetOperationTree() */
1316
1300
leftmostSelect -> intoClause = NULL ;
@@ -1460,19 +1444,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
1460
1444
qry -> limitCount = transformLimitClause (pstate , limitCount ,
1461
1445
"LIMIT" );
1462
1446
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
-
1476
1447
qry -> rtable = pstate -> p_rtable ;
1477
1448
qry -> jointree = makeFromExpr (pstate -> p_joinlist , NULL );
1478
1449
@@ -1892,44 +1863,6 @@ determineRecursiveColTypes(ParseState *pstate, Node *larg, List *nrtargetlist)
1892
1863
analyzeCTETargetList (pstate , pstate -> p_parent_cte , targetList );
1893
1864
}
1894
1865
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
-
1933
1866
1934
1867
/*
1935
1868
* transformUpdateStmt -
0 commit comments