@@ -3242,8 +3242,8 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
3242
3242
int * defmap = cstate -> defmap ;
3243
3243
ExprState * * defexprs = cstate -> defexprs ;
3244
3244
3245
- int error_level = ERROR ; /* Error level for COPY FROM input data errors */
3246
- // int exec_state = NCF_SUCCESS; /* Return code */
3245
+ /* Error level for COPY FROM input data errors */
3246
+ int error_level = ERROR ;
3247
3247
MemoryContext oldcontext = CurrentMemoryContext ;
3248
3248
3249
3249
tupDesc = RelationGetDescr (cstate -> rel );
@@ -3376,6 +3376,10 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
3376
3376
cstate -> cur_attname = NameStr (attr [m ]-> attname );
3377
3377
cstate -> cur_attval = string ;
3378
3378
3379
+ /*
3380
+ * Catch errors inside InputFunctionCall to handle
3381
+ * errors due to the type invalid syntax.
3382
+ */
3379
3383
PG_TRY ();
3380
3384
{
3381
3385
values [m ] = InputFunctionCall (& in_functions [m ],
@@ -3393,15 +3397,16 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
3393
3397
MemoryContextSwitchTo (oldcontext );
3394
3398
edata = CopyErrorData ();
3395
3399
FlushErrorState ();
3396
-
3397
- /* TODO Find an appropriate errcode */
3400
+
3401
+ /* Propagate catched ERROR sqlerrcode and message as WARNING */
3398
3402
ereport (WARNING ,
3399
- (errcode (ERRCODE_TOO_MANY_COLUMNS ),
3403
+ (errcode (edata -> sqlerrcode ),
3400
3404
errmsg ("%s at line %d col %d" , edata -> message , cstate -> cur_lineno , attnum )));
3401
3405
return NCF_SKIP ;
3402
3406
}
3403
3407
else
3404
3408
{
3409
+ /* Propagate ERROR as is if errors handling is not turned on */
3405
3410
PG_RE_THROW ();
3406
3411
}
3407
3412
}
0 commit comments