|
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.297 2004/01/23 02:13:12 neilc Exp $ |
| 9 | + * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.298 2004/04/02 21:05:32 tgl Exp $ |
10 | 10 | *
|
11 | 11 | *-------------------------------------------------------------------------
|
12 | 12 | */
|
@@ -506,7 +506,8 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
|
506 | 506 | List *sub_namespace;
|
507 | 507 | List *icolumns;
|
508 | 508 | List *attrnos;
|
509 |
| - List *attnos; |
| 509 | + List *icols; /* to become ListCell */ |
| 510 | + List *attnos; /* to become ListCell */ |
510 | 511 | List *tl;
|
511 | 512 |
|
512 | 513 | qry->commandType = CMD_INSERT;
|
@@ -665,39 +666,35 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt,
|
665 | 666 | /*
|
666 | 667 | * Prepare columns for assignment to target table.
|
667 | 668 | */
|
| 669 | + icols = icolumns; |
668 | 670 | attnos = attrnos;
|
669 |
| - /* cannot use foreach here because of possible lremove */ |
670 |
| - tl = qry->targetList; |
671 |
| - while (tl) |
| 671 | + foreach(tl, qry->targetList) |
672 | 672 | {
|
673 | 673 | TargetEntry *tle = (TargetEntry *) lfirst(tl);
|
674 | 674 | ResTarget *col;
|
675 | 675 |
|
676 |
| - /* must advance tl before lremove possibly pfree's it */ |
677 |
| - tl = lnext(tl); |
678 |
| - |
679 |
| - if (icolumns == NIL || attnos == NIL) |
| 676 | + if (icols == NIL || attnos == NIL) |
680 | 677 | ereport(ERROR,
|
681 | 678 | (errcode(ERRCODE_SYNTAX_ERROR),
|
682 | 679 | errmsg("INSERT has more expressions than target columns")));
|
683 | 680 |
|
684 |
| - col = (ResTarget *) lfirst(icolumns); |
| 681 | + col = (ResTarget *) lfirst(icols); |
685 | 682 | Assert(IsA(col, ResTarget));
|
686 | 683 |
|
687 | 684 | Assert(!tle->resdom->resjunk);
|
688 | 685 | updateTargetListEntry(pstate, tle, col->name, lfirsti(attnos),
|
689 | 686 | col->indirection);
|
690 | 687 |
|
691 |
| - icolumns = lnext(icolumns); |
| 688 | + icols = lnext(icols); |
692 | 689 | attnos = lnext(attnos);
|
693 | 690 | }
|
694 | 691 |
|
695 | 692 | /*
|
696 | 693 | * Ensure that the targetlist has the same number of entries that were
|
697 | 694 | * present in the columns list. Don't do the check unless an explicit
|
698 |
| - * columns list was given, though. statements. |
| 695 | + * columns list was given, though. |
699 | 696 | */
|
700 |
| - if (stmt->cols != NIL && (icolumns != NIL || attnos != NIL)) |
| 697 | + if (stmt->cols != NIL && (icols != NIL || attnos != NIL)) |
701 | 698 | ereport(ERROR,
|
702 | 699 | (errcode(ERRCODE_SYNTAX_ERROR),
|
703 | 700 | errmsg("INSERT has more target columns than expressions")));
|
|
0 commit comments