66 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
77 * Portions Copyright (c) 1994, Regents of the University of California
88 *
9- * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.349 2006/08/30 23:34:21 tgl Exp $
9+ * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.350 2006/09/18 00:52:14 tgl Exp $
1010 *
1111 *-------------------------------------------------------------------------
1212 */
@@ -2097,7 +2097,6 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
20972097 qry -> into = stmt -> into ;
20982098 if (stmt -> intoColNames )
20992099 applyColumnNames (qry -> targetList , stmt -> intoColNames );
2100-
21012100 qry -> intoOptions = copyObject (stmt -> intoOptions );
21022101 qry -> intoOnCommit = stmt -> intoOnCommit ;
21032102 qry -> intoTableSpaceName = stmt -> intoTableSpaceName ;
@@ -2180,8 +2179,6 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
21802179
21812180 /* Most SELECT stuff doesn't apply in a VALUES clause */
21822181 Assert (stmt -> distinctClause == NIL );
2183- Assert (stmt -> into == NULL );
2184- Assert (stmt -> intoColNames == NIL );
21852182 Assert (stmt -> targetList == NIL );
21862183 Assert (stmt -> fromClause == NIL );
21872184 Assert (stmt -> whereClause == NULL );
@@ -2281,8 +2278,16 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
22812278 Assert (pstate -> p_next_resno == 1 );
22822279 qry -> targetList = expandRelAttrs (pstate , rte , rtr -> rtindex , 0 );
22832280
2281+ /* handle any CREATE TABLE AS spec */
2282+ qry -> into = stmt -> into ;
2283+ if (stmt -> intoColNames )
2284+ applyColumnNames (qry -> targetList , stmt -> intoColNames );
2285+ qry -> intoOptions = copyObject (stmt -> intoOptions );
2286+ qry -> intoOnCommit = stmt -> intoOnCommit ;
2287+ qry -> intoTableSpaceName = stmt -> intoTableSpaceName ;
2288+
22842289 /*
2285- * The grammar does allow attaching ORDER BY, LIMIT, and FOR UPDATE
2290+ * The grammar allows attaching ORDER BY, LIMIT, and FOR UPDATE
22862291 * to a VALUES, so cope.
22872292 */
22882293 qry -> sortClause = transformSortClause (pstate ,
@@ -2355,7 +2360,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
23552360 int leftmostRTI ;
23562361 Query * leftmostQuery ;
23572362 SetOperationStmt * sostmt ;
2358- RangeVar * into ;
23592363 List * intoColNames ;
23602364 List * sortClause ;
23612365 Node * limitOffset ;
@@ -2378,19 +2382,23 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
23782382
23792383 /*
23802384 * Find leftmost leaf SelectStmt; extract the one-time-only items from it
2381- * and from the top-level node.
2385+ * and from the top-level node. (Most of the INTO options can be
2386+ * transferred to the Query immediately, but intoColNames has to be
2387+ * saved to apply below.)
23822388 */
23832389 leftmostSelect = stmt -> larg ;
23842390 while (leftmostSelect && leftmostSelect -> op != SETOP_NONE )
23852391 leftmostSelect = leftmostSelect -> larg ;
23862392 Assert (leftmostSelect && IsA (leftmostSelect , SelectStmt ) &&
23872393 leftmostSelect -> larg == NULL );
2388- into = leftmostSelect -> into ;
2394+ qry -> into = leftmostSelect -> into ;
23892395 intoColNames = leftmostSelect -> intoColNames ;
2396+ qry -> intoOptions = copyObject (leftmostSelect -> intoOptions );
2397+ qry -> intoOnCommit = leftmostSelect -> intoOnCommit ;
2398+ qry -> intoTableSpaceName = leftmostSelect -> intoTableSpaceName ;
23902399
2391- /* clear them to prevent complaints in transformSetOperationTree() */
2400+ /* clear this to prevent complaints in transformSetOperationTree() */
23922401 leftmostSelect -> into = NULL ;
2393- leftmostSelect -> intoColNames = NIL ;
23942402
23952403 /*
23962404 * These are not one-time, exactly, but we want to process them here and
@@ -2480,7 +2488,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
24802488 * top level and the leftmost subquery. We do not do this earlier because
24812489 * we do *not* want the targetnames list to be affected.
24822490 */
2483- qry -> into = into ;
24842491 if (intoColNames )
24852492 {
24862493 applyColumnNames (qry -> targetList , intoColNames );
0 commit comments