|
6 | 6 | * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
7 | 7 | * Portions Copyright (c) 1994, Regents of the University of California
|
8 | 8 | *
|
9 |
| - *$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.193 2001/07/16 05:06:58 tgl Exp $ |
| 9 | + *$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.194 2001/08/11 00:02:13 tgl Exp $ |
10 | 10 | *
|
11 | 11 | *-------------------------------------------------------------------------
|
12 | 12 | */
|
@@ -161,31 +161,36 @@ transformStmt(ParseState *pstate, Node *parseTree)
|
161 | 161 | * If a list of column names was given, run through and
|
162 | 162 | * insert these into the actual query tree. - thomas
|
163 | 163 | * 2000-03-08
|
| 164 | + * |
| 165 | + * Outer loop is over targetlist to make it easier to |
| 166 | + * skip junk targetlist entries. |
164 | 167 | */
|
165 | 168 | if (n->aliases!=NIL)
|
166 | 169 | {
|
167 |
| -inti; |
168 |
| -List*targetList=n->query->targetList; |
169 |
| - |
170 |
| -if (length(targetList)<length(n->aliases)) |
171 |
| -elog(ERROR,"CREATE VIEW specifies %d columns" |
172 |
| -" but only %d columns are present", |
173 |
| -length(targetList),length(n->aliases)); |
| 170 | +List*aliaslist=n->aliases; |
| 171 | +List*targetList; |
174 | 172 |
|
175 |
| -for (i=0;i<length(n->aliases);i++) |
| 173 | +foreach(targetList,n->query->targetList) |
176 | 174 | {
|
177 |
| -Ident*id; |
178 |
| -TargetEntry*te; |
| 175 | +TargetEntry*te= (TargetEntry*)lfirst(targetList); |
179 | 176 | Resdom*rd;
|
| 177 | +Ident*id; |
180 | 178 |
|
181 |
| -id=nth(i,n->aliases); |
182 |
| -Assert(IsA(id,Ident)); |
183 |
| -te=nth(i,targetList); |
184 | 179 | Assert(IsA(te,TargetEntry));
|
185 | 180 | rd=te->resdom;
|
186 | 181 | Assert(IsA(rd,Resdom));
|
| 182 | +if (rd->resjunk)/* junk columns don't get aliases */ |
| 183 | +continue; |
| 184 | +id= (Ident*)lfirst(aliaslist); |
| 185 | +Assert(IsA(id,Ident)); |
187 | 186 | rd->resname=pstrdup(id->name);
|
| 187 | +aliaslist=lnext(aliaslist); |
| 188 | +if (aliaslist==NIL) |
| 189 | +break;/* done assigning aliases */ |
188 | 190 | }
|
| 191 | + |
| 192 | +if (aliaslist!=NIL) |
| 193 | +elog(ERROR,"CREATE VIEW specifies more column names than columns"); |
189 | 194 | }
|
190 | 195 | result=makeNode(Query);
|
191 | 196 | result->commandType=CMD_UTILITY;
|
|