mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
CREATE VIEW with optional column name list wasn't quite right for the
case where there are resjunk columns in the query.
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.193 2001/07/16 05:06:58 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.194 2001/08/11 00:02:13 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -161,31 +161,36 @@ transformStmt(ParseState *pstate, Node *parseTree)
|
|||||||
* If a list of column names was given, run through and
|
* If a list of column names was given, run through and
|
||||||
* insert these into the actual query tree. - thomas
|
* insert these into the actual query tree. - thomas
|
||||||
* 2000-03-08
|
* 2000-03-08
|
||||||
|
*
|
||||||
|
* Outer loop is over targetlist to make it easier to
|
||||||
|
* skip junk targetlist entries.
|
||||||
*/
|
*/
|
||||||
if (n->aliases != NIL)
|
if (n->aliases != NIL)
|
||||||
{
|
{
|
||||||
int i;
|
List *aliaslist = n->aliases;
|
||||||
List *targetList = n->query->targetList;
|
List *targetList;
|
||||||
|
|
||||||
if (length(targetList) < length(n->aliases))
|
foreach(targetList, n->query->targetList)
|
||||||
elog(ERROR, "CREATE VIEW specifies %d columns"
|
|
||||||
" but only %d columns are present",
|
|
||||||
length(targetList), length(n->aliases));
|
|
||||||
|
|
||||||
for (i = 0; i < length(n->aliases); i++)
|
|
||||||
{
|
{
|
||||||
Ident *id;
|
TargetEntry *te = (TargetEntry *) lfirst(targetList);
|
||||||
TargetEntry *te;
|
|
||||||
Resdom *rd;
|
Resdom *rd;
|
||||||
|
Ident *id;
|
||||||
|
|
||||||
id = nth(i, n->aliases);
|
|
||||||
Assert(IsA(id, Ident));
|
|
||||||
te = nth(i, targetList);
|
|
||||||
Assert(IsA(te, TargetEntry));
|
Assert(IsA(te, TargetEntry));
|
||||||
rd = te->resdom;
|
rd = te->resdom;
|
||||||
Assert(IsA(rd, Resdom));
|
Assert(IsA(rd, Resdom));
|
||||||
|
if (rd->resjunk) /* junk columns don't get aliases */
|
||||||
|
continue;
|
||||||
|
id = (Ident *) lfirst(aliaslist);
|
||||||
|
Assert(IsA(id, Ident));
|
||||||
rd->resname = pstrdup(id->name);
|
rd->resname = pstrdup(id->name);
|
||||||
|
aliaslist = lnext(aliaslist);
|
||||||
|
if (aliaslist == NIL)
|
||||||
|
break; /* done assigning aliases */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (aliaslist != NIL)
|
||||||
|
elog(ERROR, "CREATE VIEW specifies more column names than columns");
|
||||||
}
|
}
|
||||||
result = makeNode(Query);
|
result = makeNode(Query);
|
||||||
result->commandType = CMD_UTILITY;
|
result->commandType = CMD_UTILITY;
|
||||||
|
Reference in New Issue
Block a user