mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Add soft error handling to some expression nodes
This adjusts the expression evaluation code for CoerceViaIO and CoerceToDomain to handle errors softly if needed. For CoerceViaIo, this means using InputFunctionCallSafe(), which provides the option to handle errors softly, instead of calling the type input function directly. For CoerceToDomain, this simply entails replacing the ereport() in ExecEvalConstraintCheck() by errsave(). In both cases, the ErrorSaveContext to be used when evaluating the expression is stored by ExecInitExprRec() in the expression's struct in the expression's ExprEvalStep. The ErrorSaveContext is passed by setting ExprState.escontext to point to it when calling ExecInitExprRec() on the expression whose errors are to be handled softly. Note that no call site of ExecInitExprRec() has been changed in this commit, so there's no functional change. This is intended for implementing new SQL/JSON expression nodes in future commits that will use to it suppress errors that may occur during type coercions. Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/CA+HiwqE4XTdfb1nW=Ojoy_tQSRhYt-q_kb6i5d4xcKyrLC1Nbg@mail.gmail.com
This commit is contained in:
@ -1177,29 +1177,27 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
|
||||
/* call input function (similar to InputFunctionCall) */
|
||||
if (!op->d.iocoerce.finfo_in->fn_strict || str != NULL)
|
||||
{
|
||||
FunctionCallInfo fcinfo_in;
|
||||
Datum d;
|
||||
bool error;
|
||||
|
||||
fcinfo_in = op->d.iocoerce.fcinfo_data_in;
|
||||
fcinfo_in->args[0].value = PointerGetDatum(str);
|
||||
fcinfo_in->args[0].isnull = *op->resnull;
|
||||
/* second and third arguments are already set up */
|
||||
/*
|
||||
* InputFunctionCallSafe() writes directly into *op->resvalue.
|
||||
* Return NULL if an error is reported.
|
||||
*/
|
||||
error = !InputFunctionCallSafe(op->d.iocoerce.finfo_in, str,
|
||||
op->d.iocoerce.typioparam, -1,
|
||||
(Node *) op->d.iocoerce.escontext,
|
||||
op->resvalue);
|
||||
if (error)
|
||||
*op->resnull = true;
|
||||
|
||||
fcinfo_in->isnull = false;
|
||||
d = FunctionCallInvoke(fcinfo_in);
|
||||
*op->resvalue = d;
|
||||
|
||||
/* Should get null result if and only if str is NULL */
|
||||
if (str == NULL)
|
||||
{
|
||||
/*
|
||||
* Should get null result if and only if str is NULL or if we
|
||||
* got an error above.
|
||||
*/
|
||||
if (str == NULL || error)
|
||||
Assert(*op->resnull);
|
||||
Assert(fcinfo_in->isnull);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert(!*op->resnull);
|
||||
Assert(!fcinfo_in->isnull);
|
||||
}
|
||||
}
|
||||
|
||||
EEO_NEXT();
|
||||
@ -3745,7 +3743,7 @@ ExecEvalConstraintCheck(ExprState *state, ExprEvalStep *op)
|
||||
{
|
||||
if (!*op->d.domaincheck.checknull &&
|
||||
!DatumGetBool(*op->d.domaincheck.checkvalue))
|
||||
ereport(ERROR,
|
||||
errsave((Node *) op->d.domaincheck.escontext,
|
||||
(errcode(ERRCODE_CHECK_VIOLATION),
|
||||
errmsg("value for domain %s violates check constraint \"%s\"",
|
||||
format_type_be(op->d.domaincheck.resulttype),
|
||||
|
Reference in New Issue
Block a user