6
6
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
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 $
10
10
*
11
11
*-------------------------------------------------------------------------
12
12
*/
@@ -2097,7 +2097,6 @@ transformSelectStmt(ParseState *pstate, SelectStmt *stmt)
2097
2097
qry -> into = stmt -> into ;
2098
2098
if (stmt -> intoColNames )
2099
2099
applyColumnNames (qry -> targetList , stmt -> intoColNames );
2100
-
2101
2100
qry -> intoOptions = copyObject (stmt -> intoOptions );
2102
2101
qry -> intoOnCommit = stmt -> intoOnCommit ;
2103
2102
qry -> intoTableSpaceName = stmt -> intoTableSpaceName ;
@@ -2180,8 +2179,6 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
2180
2179
2181
2180
/* Most SELECT stuff doesn't apply in a VALUES clause */
2182
2181
Assert (stmt -> distinctClause == NIL );
2183
- Assert (stmt -> into == NULL );
2184
- Assert (stmt -> intoColNames == NIL );
2185
2182
Assert (stmt -> targetList == NIL );
2186
2183
Assert (stmt -> fromClause == NIL );
2187
2184
Assert (stmt -> whereClause == NULL );
@@ -2281,8 +2278,16 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt)
2281
2278
Assert (pstate -> p_next_resno == 1 );
2282
2279
qry -> targetList = expandRelAttrs (pstate , rte , rtr -> rtindex , 0 );
2283
2280
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
+
2284
2289
/*
2285
- * The grammar does allow attaching ORDER BY, LIMIT, and FOR UPDATE
2290
+ * The grammar allows attaching ORDER BY, LIMIT, and FOR UPDATE
2286
2291
* to a VALUES, so cope.
2287
2292
*/
2288
2293
qry -> sortClause = transformSortClause (pstate ,
@@ -2355,7 +2360,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
2355
2360
int leftmostRTI ;
2356
2361
Query * leftmostQuery ;
2357
2362
SetOperationStmt * sostmt ;
2358
- RangeVar * into ;
2359
2363
List * intoColNames ;
2360
2364
List * sortClause ;
2361
2365
Node * limitOffset ;
@@ -2378,19 +2382,23 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
2378
2382
2379
2383
/*
2380
2384
* 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.)
2382
2388
*/
2383
2389
leftmostSelect = stmt -> larg ;
2384
2390
while (leftmostSelect && leftmostSelect -> op != SETOP_NONE )
2385
2391
leftmostSelect = leftmostSelect -> larg ;
2386
2392
Assert (leftmostSelect && IsA (leftmostSelect , SelectStmt ) &&
2387
2393
leftmostSelect -> larg == NULL );
2388
- into = leftmostSelect -> into ;
2394
+ qry -> into = leftmostSelect -> into ;
2389
2395
intoColNames = leftmostSelect -> intoColNames ;
2396
+ qry -> intoOptions = copyObject (leftmostSelect -> intoOptions );
2397
+ qry -> intoOnCommit = leftmostSelect -> intoOnCommit ;
2398
+ qry -> intoTableSpaceName = leftmostSelect -> intoTableSpaceName ;
2390
2399
2391
- /* clear them to prevent complaints in transformSetOperationTree() */
2400
+ /* clear this to prevent complaints in transformSetOperationTree() */
2392
2401
leftmostSelect -> into = NULL ;
2393
- leftmostSelect -> intoColNames = NIL ;
2394
2402
2395
2403
/*
2396
2404
* These are not one-time, exactly, but we want to process them here and
@@ -2480,7 +2488,6 @@ transformSetOperationStmt(ParseState *pstate, SelectStmt *stmt)
2480
2488
* top level and the leftmost subquery. We do not do this earlier because
2481
2489
* we do *not* want the targetnames list to be affected.
2482
2490
*/
2483
- qry -> into = into ;
2484
2491
if (intoColNames )
2485
2492
{
2486
2493
applyColumnNames (qry -> targetList , intoColNames );
0 commit comments