77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.85 1998/09/01 04:30:15 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.86 1998/09/03 14:21:06 thomas Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -269,8 +269,8 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
269269int ndef = pstate -> p_target_relation -> rd_att -> constr -> num_defval ;
270270
271271/*
272- * if stmt->cols == NIL then makeTargetNames returns list of all
273- *attrs: have toshorter icolumns list...
272+ * if stmt->cols == NIL then makeTargetNames returns list of all attrs.
273+ *May have toshorten icolumns list...
274274 */
275275if (stmt -> cols == NIL )
276276{
@@ -279,11 +279,26 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
279279
280280foreach (extrl ,icolumns )
281281{
282+ /*
283+ * decrements first, so if we started with zero items
284+ * it will now be negative
285+ */
282286if (-- i <=0 )
283287break ;
284288}
285- freeList (lnext (extrl ));
286- lnext (extrl )= NIL ;
289+ /*
290+ * this an index into the targetList,
291+ * so make sure we had one to start...
292+ */
293+ if (i >=0 )
294+ {
295+ freeList (lnext (extrl ));
296+ lnext (extrl )= NIL ;
297+ }
298+ else
299+ {
300+ icolumns = NIL ;
301+ }
287302}
288303
289304while (ndef -- > 0 )
@@ -295,7 +310,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
295310foreach (tl ,icolumns )
296311{
297312id = (Ident * )lfirst (tl );
298- if (! namestrcmp (& (att [defval [ndef ].adnum - 1 ]-> attname ),id -> name ))
313+ if (namestrcmp (& (att [defval [ndef ].adnum - 1 ]-> attname ),id -> name )== 0 )
299314break ;
300315}
301316if (tl != NIL )/* something given for this attr */