8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -1258,6 +1258,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
1258
1258
ExprState * * constraintexprs ;
1259
1259
bool hasConstraints = false;
1260
1260
int i ;
1261
+ int attnum ;
1261
1262
List * cur ;
1262
1263
Oid in_func_oid ;
1263
1264
Datum * values ;
@@ -1317,39 +1318,39 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
1317
1318
defexprs = (ExprState * * ) palloc ((num_phys_attrs + 1 ) * sizeof (ExprState * ));
1318
1319
constraintexprs = (ExprState * * ) palloc0 ((num_phys_attrs + 1 ) * sizeof (ExprState * ));
1319
1320
1320
- for (i = 0 ; i < num_phys_attrs ; i ++ )
1321
+ for (attnum = 1 ; attnum <= num_phys_attrs ; attnum ++ )
1321
1322
{
1322
1323
/* We don't need info for dropped attributes */
1323
- if (attr [i ]-> attisdropped )
1324
+ if (attr [attnum - 1 ]-> attisdropped )
1324
1325
continue ;
1325
1326
1326
1327
/* Fetch the input function and typelem info */
1327
1328
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 ]);
1330
1331
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 ]);
1334
1335
1335
1336
/* Get default info if needed */
1336
- if (!intMember (i + 1 , attnumlist ))
1337
+ if (!intMember (attnum , attnumlist ))
1337
1338
{
1338
1339
/* attribute is NOT to be copied from input */
1339
1340
/* use default value if one exists */
1340
- Node * defexpr = build_column_default (rel , i + 1 );
1341
+ Node * defexpr = build_column_default (rel , attnum );
1341
1342
1342
1343
if (defexpr != NULL )
1343
1344
{
1344
1345
defexprs [num_defaults ] = ExecPrepareExpr ((Expr * ) defexpr ,
1345
1346
estate );
1346
- defmap [num_defaults ] = i ;
1347
+ defmap [num_defaults ] = attnum - 1 ;
1347
1348
num_defaults ++ ;
1348
1349
}
1349
1350
}
1350
1351
1351
1352
/* 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' )
1353
1354
{
1354
1355
Param * prm ;
1355
1356
Node * node ;
@@ -1365,14 +1366,14 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
1365
1366
prm = makeNode (Param );
1366
1367
prm -> paramkind = PARAM_EXEC ;
1367
1368
prm -> paramid = 0 ;
1368
- prm -> paramtype = getBaseType (attr [i ]-> atttypid );
1369
+ prm -> paramtype = getBaseType (attr [attnum - 1 ]-> atttypid );
1369
1370
1370
1371
node = coerce_to_domain ((Node * ) prm ,
1371
1372
prm -> paramtype ,
1372
- attr [i ]-> atttypid ,
1373
+ attr [attnum - 1 ]-> atttypid ,
1373
1374
COERCE_IMPLICIT_CAST );
1374
1375
1375
- constraintexprs [i ] = ExecPrepareExpr ((Expr * ) node ,
1376
+ constraintexprs [attnum - 1 ] = ExecPrepareExpr ((Expr * ) node ,
1376
1377
estate );
1377
1378
hasConstraints = true;
1378
1379
}
0 commit comments