88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.219 2004/04/06 13:21:33 momjian Exp $
11+ * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.220 2004/04/15 22:36:03 momjian Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -1258,6 +1258,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
12581258 ExprState * * constraintexprs ;
12591259 bool hasConstraints = false;
12601260 int i ;
1261+ int attnum ;
12611262 List * cur ;
12621263 Oid in_func_oid ;
12631264 Datum * values ;
@@ -1317,39 +1318,39 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
13171318 defexprs = (ExprState * * ) palloc ((num_phys_attrs + 1 ) * sizeof (ExprState * ));
13181319 constraintexprs = (ExprState * * ) palloc0 ((num_phys_attrs + 1 ) * sizeof (ExprState * ));
13191320
1320- for (i = 0 ; i < num_phys_attrs ; i ++ )
1321+ for (attnum = 1 ; attnum <= num_phys_attrs ; attnum ++ )
13211322 {
13221323 /* We don't need info for dropped attributes */
1323- if (attr [i ]-> attisdropped )
1324+ if (attr [attnum - 1 ]-> attisdropped )
13241325 continue ;
13251326
13261327 /* Fetch the input function and typelem info */
13271328 if (binary )
1328- getTypeBinaryInputInfo (attr [i ]-> atttypid ,
1329- & in_func_oid , & elements [i ]);
1329+ getTypeBinaryInputInfo (attr [attnum - 1 ]-> atttypid ,
1330+ & in_func_oid , & elements [attnum - 1 ]);
13301331 else
1331- getTypeInputInfo (attr [i ]-> atttypid ,
1332- & in_func_oid , & elements [i ]);
1333- fmgr_info (in_func_oid , & in_functions [i ]);
1332+ getTypeInputInfo (attr [attnum - 1 ]-> atttypid ,
1333+ & in_func_oid , & elements [attnum - 1 ]);
1334+ fmgr_info (in_func_oid , & in_functions [attnum - 1 ]);
13341335
13351336 /* Get default info if needed */
1336- if (!intMember (i + 1 , attnumlist ))
1337+ if (!intMember (attnum , attnumlist ))
13371338 {
13381339 /* attribute is NOT to be copied from input */
13391340 /* use default value if one exists */
1340- Node * defexpr = build_column_default (rel , i + 1 );
1341+ Node * defexpr = build_column_default (rel , attnum );
13411342
13421343 if (defexpr != NULL )
13431344 {
13441345 defexprs [num_defaults ] = ExecPrepareExpr ((Expr * ) defexpr ,
13451346 estate );
1346- defmap [num_defaults ] = i ;
1347+ defmap [num_defaults ] = attnum - 1 ;
13471348 num_defaults ++ ;
13481349 }
13491350 }
13501351
13511352 /* If it's a domain type, set up to check domain constraints */
1352- if (get_typtype (attr [i ]-> atttypid ) == 'd' )
1353+ if (get_typtype (attr [attnum - 1 ]-> atttypid ) == 'd' )
13531354 {
13541355 Param * prm ;
13551356 Node * node ;
@@ -1365,14 +1366,14 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
13651366 prm = makeNode (Param );
13661367 prm -> paramkind = PARAM_EXEC ;
13671368 prm -> paramid = 0 ;
1368- prm -> paramtype = getBaseType (attr [i ]-> atttypid );
1369+ prm -> paramtype = getBaseType (attr [attnum - 1 ]-> atttypid );
13691370
13701371 node = coerce_to_domain ((Node * ) prm ,
13711372 prm -> paramtype ,
1372- attr [i ]-> atttypid ,
1373+ attr [attnum - 1 ]-> atttypid ,
13731374 COERCE_IMPLICIT_CAST );
13741375
1375- constraintexprs [i ] = ExecPrepareExpr ((Expr * ) node ,
1376+ constraintexprs [attnum - 1 ] = ExecPrepareExpr ((Expr * ) node ,
13761377 estate );
13771378 hasConstraints = true;
13781379 }
0 commit comments