8000 [Rebased] Errors handling during COPY FROM by ololobus · Pull Request #3 · ololobus/postgres · GitHub
[go: up one dir, main page]

Skip to content

[Rebased] Errors handling during COPY FROM #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Propagate catched SQL error code to warning
  • Loading branch information
ololobus committed Jul 10, 2017
commit c4c93114eae5bbe6850e07c79f21be51f3f9b76c
15 changes: 10 additions & 5 deletions src/backend/commands/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -3302,8 +3302,8 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
int *defmap = cstate->defmap;
ExprState **defexprs = cstate->defexprs;

int error_level = ERROR; /* Error level for COPY FROM input data errors */
// int exec_state = NCF_SUCCESS; /* Return code */
/* Error level for COPY FROM input data errors */
int error_level = ERROR;
MemoryContext oldcontext = CurrentMemoryContext;

tupDesc = RelationGetDescr(cstate->rel);
Expand Down Expand Up @@ -3436,6 +3436,10 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
cstate->cur_attname = NameStr(attr[m]->attname);
cstate->cur_attval = string;

/*
* Catch errors inside InputFunctionCall to handle
* errors due to the type invalid syntax.
*/
PG_TRY();
{
values[m] = InputFunctionCall(&in_functions[m],
Expand All @@ -3453,15 +3457,16 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext,
MemoryContextSwitchTo(oldcontext);
edata = CopyErrorData();
FlushErrorState();
/* TODO Find an appropriate errcode */

/* Propagate catched ERROR sqlerrcode and message as WARNING */
ereport(WARNING,
(errcode(ERRCODE_TOO_MANY_COLUMNS),
(errcode(edata->sqlerrcode),
errmsg("%s at line %d col %d", edata->message, cstate->cur_lineno, attnum)));
return NCF_SKIP;
}
else
{
/* Propagate ERROR as is if errors handling is not turned on */
PG_RE_THROW();
}
}
Expand Down
0