|
6 | 6 | * Portions Copyright (c) 1996-2003, 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.292 2003/11/29 19:51:51 pgsql Exp $ |
| 9 | + *$PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.293 2004/01/05 20:58:58 neilc Exp $ |
10 | 10 | * |
11 | 11 | *------------------------------------------------------------------------- |
12 | 12 | */ |
@@ -95,6 +95,8 @@ typedef struct |
95 | 95 | staticList*do_parse_analyze(Node*parseTree,ParseState*pstate); |
96 | 96 | staticQuery*transformStmt(ParseState*pstate,Node*stmt, |
97 | 97 | List**extras_before,List**extras_after); |
| 98 | +staticQuery*transformViewStmt(ParseState*pstate,ViewStmt*stmt, |
| 99 | +List**extras_before,List**extras_after); |
98 | 100 | staticQuery*transformDeleteStmt(ParseState*pstate,DeleteStmt*stmt); |
99 | 101 | staticQuery*transformInsertStmt(ParseState*pstate,InsertStmt*stmt, |
100 | 102 | List**extras_before,List**extras_after); |
@@ -322,51 +324,8 @@ transformStmt(ParseState *pstate, Node *parseTree, |
322 | 324 | break; |
323 | 325 |
|
324 | 326 | caseT_ViewStmt: |
325 | | -{ |
326 | | -ViewStmt*n= (ViewStmt*)parseTree; |
327 | | - |
328 | | -n->query=transformStmt(pstate, (Node*)n->query, |
329 | | -extras_before,extras_after); |
330 | | - |
331 | | -/* |
332 | | - * If a list of column names was given, run through and |
333 | | - * insert these into the actual query tree. - thomas |
334 | | - * 2000-03-08 |
335 | | - * |
336 | | - * Outer loop is over targetlist to make it easier to skip |
337 | | - * junk targetlist entries. |
338 | | - */ |
339 | | -if (n->aliases!=NIL) |
340 | | -{ |
341 | | -List*aliaslist=n->aliases; |
342 | | -List*targetList; |
343 | | - |
344 | | -foreach(targetList,n->query->targetList) |
345 | | -{ |
346 | | -TargetEntry*te= (TargetEntry*)lfirst(targetList); |
347 | | -Resdom*rd; |
348 | | - |
349 | | -Assert(IsA(te,TargetEntry)); |
350 | | -rd=te->resdom; |
351 | | -Assert(IsA(rd,Resdom)); |
352 | | -/* junk columns don't get aliases */ |
353 | | -if (rd->resjunk) |
354 | | -continue; |
355 | | -rd->resname=pstrdup(strVal(lfirst(aliaslist))); |
356 | | -aliaslist=lnext(aliaslist); |
357 | | -if (aliaslist==NIL) |
358 | | -break;/* done assigning aliases */ |
359 | | -} |
360 | | - |
361 | | -if (aliaslist!=NIL) |
362 | | -ereport(ERROR, |
363 | | -(errcode(ERRCODE_SYNTAX_ERROR), |
364 | | -errmsg("CREATE VIEW specifies more column names than columns"))); |
365 | | -} |
366 | | -result=makeNode(Query); |
367 | | -result->commandType=CMD_UTILITY; |
368 | | -result->utilityStmt= (Node*)n; |
369 | | -} |
| 327 | +result=transformViewStmt(pstate, (ViewStmt*)parseTree, |
| 328 | +extras_before,extras_after); |
370 | 329 | break; |
371 | 330 |
|
372 | 331 | caseT_ExplainStmt: |
@@ -443,6 +402,57 @@ transformStmt(ParseState *pstate, Node *parseTree, |
443 | 402 | returnresult; |
444 | 403 | } |
445 | 404 |
|
| 405 | +staticQuery* |
| 406 | +transformViewStmt(ParseState*pstate,ViewStmt*stmt, |
| 407 | +List**extras_before,List**extras_after) |
| 408 | +{ |
| 409 | +Query*result=makeNode(Query); |
| 410 | + |
| 411 | +result->commandType=CMD_UTILITY; |
| 412 | +result->utilityStmt= (Node*)stmt; |
| 413 | + |
| 414 | +stmt->query=transformStmt(pstate, (Node*)stmt->query, |
| 415 | +extras_before,extras_after); |
| 416 | + |
| 417 | +/* |
| 418 | + * If a list of column names was given, run through and insert |
| 419 | + * these into the actual query tree. - thomas 2000-03-08 |
| 420 | + * |
| 421 | + * Outer loop is over targetlist to make it easier to skip junk |
| 422 | + * targetlist entries. |
| 423 | + */ |
| 424 | +if (stmt->aliases!=NIL) |
| 425 | +{ |
| 426 | +List*aliaslist=stmt->aliases; |
| 427 | +List*targetList; |
| 428 | + |
| 429 | +foreach(targetList,stmt->query->targetList) |
| 430 | +{ |
| 431 | +TargetEntry*te= (TargetEntry*)lfirst(targetList); |
| 432 | +Resdom*rd; |
| 433 | + |
| 434 | +Assert(IsA(te,TargetEntry)); |
| 435 | +rd=te->resdom; |
| 436 | +Assert(IsA(rd,Resdom)); |
| 437 | +/* junk columns don't get aliases */ |
| 438 | +if (rd->resjunk) |
| 439 | +continue; |
| 440 | +rd->resname=pstrdup(strVal(lfirst(aliaslist))); |
| 441 | +aliaslist=lnext(aliaslist); |
| 442 | +if (aliaslist==NIL) |
| 443 | +break;/* done assigning aliases */ |
| 444 | +} |
| 445 | + |
| 446 | +if (aliaslist!=NIL) |
| 447 | +ereport(ERROR, |
| 448 | +(errcode(ERRCODE_SYNTAX_ERROR), |
| 449 | +errmsg("CREATE VIEW specifies more column " |
| 450 | +"names than columns"))); |
| 451 | +} |
| 452 | + |
| 453 | +returnresult; |
| 454 | +} |
| 455 | + |
446 | 456 | /* |
447 | 457 | * transformDeleteStmt - |
448 | 458 | * transforms a Delete Statement |
|