@@ -252,7 +252,8 @@ typedef JsonPathBool (*JsonPathPredicateCallback) (JsonPathItem *jsp,
252252JsonbValue * larg ,
253253JsonbValue * rarg ,
254254void * param );
255- typedef Numeric (* BinaryArithmFunc ) (Numeric num1 ,Numeric num2 ,bool * error );
255+ typedef Numeric (* BinaryArithmFunc ) (Numeric num1 ,Numeric num2 ,
256+ Node * escontext );
256257
257258static JsonPathExecResult executeJsonPath (JsonPath * path ,void * vars ,
258259JsonPathGetVarCallback getVar ,
@@ -808,23 +809,23 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
808809
809810case jpiAdd :
810811return executeBinaryArithmExpr (cxt ,jsp ,jb ,
811- numeric_add_opt_error ,found );
812+ numeric_add_safe ,found );
812813
813814case jpiSub :
814815return executeBinaryArithmExpr (cxt ,jsp ,jb ,
815- numeric_sub_opt_error ,found );
816+ numeric_sub_safe ,found );
816817
817818case jpiMul :
818819return executeBinaryArithmExpr (cxt ,jsp ,jb ,
819- numeric_mul_opt_error ,found );
820+ numeric_mul_safe ,found );
820821
821822case jpiDiv :
822823return executeBinaryArithmExpr (cxt ,jsp ,jb ,
823- numeric_div_opt_error ,found );
824+ numeric_div_safe ,found );
824825
825826case jpiMod :
826827return executeBinaryArithmExpr (cxt ,jsp ,jb ,
827- numeric_mod_opt_error ,found );
828+ numeric_mod_safe ,found );
828829
829830case jpiPlus :
830831return executeUnaryArithmExpr (cxt ,jsp ,jb ,NULL ,found );
@@ -1269,11 +1270,12 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
12691270
12701271if (jb -> type == jbvNumeric )
12711272{
1272- bool have_error ;
1273+ ErrorSaveContext escontext = { T_ErrorSaveContext } ;
12731274int64 val ;
12741275
1275- val = numeric_int8_opt_error (jb -> val .numeric ,& have_error );
1276- if (have_error )
1276+ val = numeric_int8_safe (jb -> val .numeric ,
1277+ (Node * )& escontext );
1278+ if (escontext .error_occurred )
12771279RETURN_ERROR (ereport (ERROR ,
12781280 (errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
12791281errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type %s" ,
@@ -1466,7 +1468,6 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
14661468Datum dtypmod ;
14671469int32 precision ;
14681470int32 scale = 0 ;
1469- bool have_error ;
14701471bool noerr ;
14711472ArrayType * arrtypmod ;
14721473Datum datums [2 ];
@@ -1478,9 +1479,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
14781479if (elem .type != jpiNumeric )
14791480elog (ERROR ,"invalid jsonpath item type for .decimal() precision" );
14801481
1481- precision = numeric_int4_opt_error (jspGetNumeric (& elem ),
1482- & have_error );
1483- if (have_error )
1482+ precision = numeric_int4_safe (jspGetNumeric (& elem ),
1483+ ( Node * ) & escontext );
1484+ if (escontext . error_occurred )
14841485RETURN_ERROR (ereport (ERROR ,
14851486 (errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
14861487errmsg ("precision of jsonpath item method .%s() is out of range for type integer" ,
@@ -1492,9 +1493,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
14921493if (elem .type != jpiNumeric )
14931494elog (ERROR ,"invalid jsonpath item type for .decimal() scale" );
14941495
1495- scale = numeric_int4_opt_error (jspGetNumeric (& elem ),
1496- & have_error );
1497- if (have_error )
1496+ scale = numeric_int4_safe (jspGetNumeric (& elem ),
1497+ ( Node * ) & escontext );
1498+ if (escontext . error_occurred )
14981499RETURN_ERROR (ereport (ERROR ,
14991500 (errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
15001501errmsg ("scale of jsonpath item method .%s() is out of range for type integer" ,
@@ -1550,11 +1551,12 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
15501551
15511552if (jb -> type == jbvNumeric )
15521553{
1553- bool have_error ;
15541554int32 val ;
1555+ ErrorSaveContext escontext = {T_ErrorSaveContext };
15551556
1556- val = numeric_int4_opt_error (jb -> val .numeric ,& have_error );
1557- if (have_error )
1557+ val = numeric_int4_safe (jb -> val .numeric ,
1558+ (Node * )& escontext );
1559+ if (escontext .error_occurred )
15581560RETURN_ERROR (ereport (ERROR ,
15591561 (errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
15601562errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type %s" ,
@@ -2149,11 +2151,11 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
21492151}
21502152else
21512153{
2152- bool error = false ;
2154+ ErrorSaveContext escontext = { T_ErrorSaveContext } ;
21532155
2154- res = func (lval -> val .numeric ,rval -> val .numeric ,& error );
2156+ res = func (lval -> val .numeric ,rval -> val .numeric ,( Node * ) & escontext );
21552157
2156- if (error )
2158+ if (escontext . error_occurred )
21572159return jperError ;
21582160}
21592161
@@ -2433,17 +2435,17 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
24332435if (jsp -> type != jpiDatetime && jsp -> type != jpiDate &&
24342436jsp -> content .arg )
24352437{
2436- bool have_error ;
2438+ ErrorSaveContext escontext = { T_ErrorSaveContext } ;
24372439
24382440jspGetArg (jsp ,& elem );
24392441
24402442if (elem .type != jpiNumeric )
24412443elog (ERROR ,"invalid jsonpath item type for %s argument" ,
24422444jspOperationName (jsp -> type ));
24432445
2444- time_precision = numeric_int4_opt_error (jspGetNumeric (& elem ),
2445- & have_error );
2446- if (have_error )
2446+ time_precision = numeric_int4_safe (jspGetNumeric (& elem ),
2447+ ( Node * ) & escontext );
2448+ if (escontext . error_occurred )
24472449RETURN_ERROR (ereport (ERROR ,
24482450 (errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
24492451errmsg ("time precision of jsonpath item method .%s() is out of range for type integer" ,
@@ -3462,7 +3464,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
34623464JsonValueList found = {0 };
34633465JsonPathExecResult res = executeItem (cxt ,jsp ,jb ,& found );
34643466Datum numeric_index ;
3465- bool have_error = false ;
3467+ ErrorSaveContext escontext = { T_ErrorSaveContext } ;
34663468
34673469if (jperIsError (res ))
34683470return res ;
@@ -3477,10 +3479,10 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
34773479NumericGetDatum (jbv -> val .numeric ),
34783480Int32GetDatum (0 ));
34793481
3480- * index = numeric_int4_opt_error (DatumGetNumeric (numeric_index ),
3481- & have_error );
3482+ * index = numeric_int4_safe (DatumGetNumeric (numeric_index ),
3483+ ( Node * ) & escontext );
34823484
3483- if (have_error )
3485+ if (escontext . error_occurred )
34843486RETURN_ERROR (ereport (ERROR ,
34853487 (errcode (ERRCODE_INVALID_SQL_JSON_SUBSCRIPT ),
34863488errmsg ("jsonpath array subscript is out of integer range" ))));