8000 Propagate catched SQL error code to warning · ololobus/postgres@349f498 · GitHub
[go: up one dir, main page]

Skip to content

Commit 349f498

Browse files
committed
Propagate catched SQL error code to warning
1 parent 9828c84 commit 349f498

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/backend/commands/copy.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,8 +3242,8 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
32423242
int *defmap = cstate->defmap;
32433243
ExprState **defexprs = cstate->defexprs;
32443244

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;
32473247
MemoryContext oldcontext = CurrentMemoryContext;
32483248

32493249
tupDesc = RelationGetDescr(cstate->rel);
@@ -3376,6 +3376,10 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
33763376
cstate->cur_attname = NameStr(attr[m]->attname);
33773377
cstate->cur_attval = string;
33783378

3379+
/*
3380+
* Catch errors inside InputFunctionCall to handle
3381+
* errors due to the type invalid syntax.
3382+
*/
33793383
PG_TRY();
33803384
{
33813385
values[m] = InputFunctionCall(&in_functions[m],
@@ -3393,15 +3397,16 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
33933397
MemoryContextSwitchTo(oldcontext);
33943398
edata = CopyErrorData();
33953399
FlushErrorState();
3396-
3397-
/* TODO Find an appropriate errcode */
3400+
3401+
/* Propagate catched ERROR sqlerrcode and message as WARNING */
33983402
ereport(WARNING,
3399-
(errcode(ERRCODE_TOO_MANY_COLUMNS),
3403+
(errcode(edata->sqlerrcode),
34003404
errmsg("%s at line %d col %d", edata->message, cstate->cur_lineno, attnum)));
34013405
return NCF_SKIP;
34023406
}
34033407
else
34043408
{
3409+
/* Propagate ERROR as is if errors handling is not turned on */
34053410
PG_RE_THROW();
34063411
}
34073412
}

0 commit comments

Comments
 (0)
0