* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.159 2001/10/25 05:49:30 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.160 2001/11/05 05:00:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (from->into)
newnode->into = pstrdup(from->into);
newnode->istemp = from->istemp;
+ Node_Copy(from, newnode, intoColNames);
Node_Copy(from, newnode, targetList);
Node_Copy(from, newnode, fromClause);
Node_Copy(from, newnode, whereClause);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.107 2001/10/25 05:49:30 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.108 2001/11/05 05:00:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
return false;
if (a->istemp != b->istemp)
return false;
+ if (!equal(a->intoColNames, b->intoColNames))
+ return false;
if (!equal(a->targetList, b->targetList))
return false;
if (!equal(a->fromClause, b->fromClause))
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.209 2001/11/04 03:08:11 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.210 2001/11/05 05:00:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
CreateStmtContext *cxt);
static Node *transformTypeRefs(ParseState *pstate, Node *stmt);
+static void applyColumnNames(List *dst, List *src);
static void transformTypeRefsList(ParseState *pstate, List *l);
static void transformTypeRef(ParseState *pstate, TypeName *tn);
static List *getSetColTypes(ParseState *pstate, Node *node);
/* process the FROM clause */
transformFromClause(pstate, stmt->fromClause);
- /* transform targetlist and WHERE */
+ /* transform targetlist */
qry->targetList = transformTargetList(pstate, stmt->targetList);
+ if (stmt->intoColNames)
+ applyColumnNames(qry->targetList, stmt->intoColNames);
+
+ /* transform WHERE */
qual = transformWhereClause(pstate, stmt->whereClause);
/*
SetOperationStmt *sostmt;
char *into;
bool istemp;
+ List *intoColNames;
char *portalname;
bool binary;
List *sortClause;
leftmostSelect->larg == NULL);
into = leftmostSelect->into;
istemp = leftmostSelect->istemp;
+ intoColNames = leftmostSelect->intoColNames;
portalname = stmt->portalname;
binary = stmt->binary;
/* clear them to prevent complaints in transformSetOperationTree() */
leftmostSelect->into = NULL;
leftmostSelect->istemp = false;
+ leftmostSelect->intoColNames = NIL;
stmt->portalname = NULL;
stmt->binary = false;
qry->isBinary = FALSE;
}
+ if (intoColNames)
+ applyColumnNames(qry->targetList, intoColNames);
+
/*
* As a first step towards supporting sort clauses that are
* expressions using the output columns, generate a namespace entry
}
}
+/* Attach column names from a ColumnDef list to a TargetEntry list */
+static void
+applyColumnNames(List *dst, List *src)
+{
+ if (length(src) > length(dst))
+ elog(ERROR,"CREATE TABLE AS specifies too many column names");
+
+ while (src != NIL && dst != NIL)
+ {
+ TargetEntry *d = (TargetEntry *) lfirst(dst);
+ ColumnDef *s = (ColumnDef *) lfirst(src);
+
+ Assert(d->resdom && !d->resdom->resjunk);
+
+ d->resdom->resname = pstrdup(s->colname);
+
+ dst = lnext(dst);
+ src = lnext(src);
+ }
+}
+
/*
* transformUpdateStmt -
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.271 2001/10/31 04:49:43 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.272 2001/11/05 05:00:14 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
static Node *makeStringConst(char *str, TypeName *typename);
static Node *makeFloatConst(char *str);
static Node *makeRowExpr(char *opr, List *largs, List *rargs);
-static void mapTargetColumns(List *source, List *target);
static SelectStmt *findLeftmostSelect(SelectStmt *node);
static void insertSelectOptions(SelectStmt *stmt,
List *sortClause, List *forUpdate,
*/
SelectStmt *n = findLeftmostSelect((SelectStmt *) $7);
if (n->into != NULL)
- elog(ERROR,"CREATE TABLE / AS SELECT may not specify INTO");
+ elog(ERROR,"CREATE TABLE AS may not specify INTO");
n->istemp = $2;
n->into = $4;
- if ($5 != NIL)
- mapTargetColumns($5, n->targetList);
+ n->intoColNames = $5;
$$ = $7;
}
;
n->targetList = $3;
n->istemp = (bool) ((Value *) lfirst($4))->val.ival;
n->into = (char *) lnext($4);
+ n->intoColNames = NIL;
n->fromClause = $5;
n->whereClause = $6;
n->groupClause = $7;
return expr;
}
-static void
-mapTargetColumns(List *src, List *dst)
-{
- ColumnDef *s;
- ResTarget *d;
-
- if (length(src) != length(dst))
- elog(ERROR,"CREATE TABLE / AS SELECT has mismatched column count");
-
- while ((src != NIL) && (dst != NIL))
- {
- s = (ColumnDef *)lfirst(src);
- d = (ResTarget *)lfirst(dst);
-
- d->name = s->colname;
-
- src = lnext(src);
- dst = lnext(dst);
- }
-} /* mapTargetColumns() */
-
-
/* findLeftmostSelect()
* Find the leftmost component SelectStmt in a set-operation parsetree.
*/
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: parsenodes.h,v 1.149 2001/10/28 06:26:07 momjian Exp $
+ * $Id: parsenodes.h,v 1.150 2001/11/05 05:00:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* DISTINCT) */
char *into; /* name of table (for select into table) */
bool istemp; /* into is a temp table? */
+ List *intoColNames; /* column names for into table */
List *targetList; /* the target list (of ResTarget) */
List *fromClause; /* the FROM clause */
Node *whereClause; /* WHERE qualification */