@@ -252,7 +252,8 @@ typedef JsonPathBool (*JsonPathPredicateCallback) (JsonPathItem *jsp,
252
252
JsonbValue * larg ,
253
253
JsonbValue * rarg ,
254
254
void * param );
255
- typedef Numeric (* BinaryArithmFunc ) (Numeric num1 ,Numeric num2 ,bool * error );
255
+ typedef Numeric (* BinaryArithmFunc ) (Numeric num1 ,Numeric num2 ,
256
+ Node * escontext );
256
257
257
258
static JsonPathExecResult executeJsonPath (JsonPath * path ,void * vars ,
258
259
JsonPathGetVarCallback getVar ,
@@ -808,23 +809,23 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
808
809
809
810
case jpiAdd :
810
811
return executeBinaryArithmExpr (cxt ,jsp ,jb ,
811
- numeric_add_opt_error ,found );
812
+ numeric_add_safe ,found );
812
813
813
814
case jpiSub :
814
815
return executeBinaryArithmExpr (cxt ,jsp ,jb ,
815
- numeric_sub_opt_error ,found );
816
+ numeric_sub_safe ,found );
816
817
817
818
case jpiMul :
818
819
return executeBinaryArithmExpr (cxt ,jsp ,jb ,
819
- numeric_mul_opt_error ,found );
820
+ numeric_mul_safe ,found );
820
821
821
822
case jpiDiv :
822
823
return executeBinaryArithmExpr (cxt ,jsp ,jb ,
823
- numeric_div_opt_error ,found );
824
+ numeric_div_safe ,found );
824
825
825
826
case jpiMod :
826
827
return executeBinaryArithmExpr (cxt ,jsp ,jb ,
827
- numeric_mod_opt_error ,found );
828
+ numeric_mod_safe ,found );
828
829
829
830
case jpiPlus :
830
831
return executeUnaryArithmExpr (cxt ,jsp ,jb ,NULL ,found );
@@ -1269,11 +1270,12 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1269
1270
1270
1271
if (jb -> type == jbvNumeric )
1271
1272
{
1272
- bool have_error ;
1273
+ ErrorSaveContext escontext = { T_ErrorSaveContext } ;
1273
1274
int64 val ;
1274
1275
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 )
1277
1279
RETURN_ERROR (ereport (ERROR ,
1278
1280
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1279
1281
errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type %s" ,
@@ -1466,7 +1468,6 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1466
1468
Datum dtypmod ;
1467
1469
int32 precision ;
1468
1470
int32 scale = 0 ;
1469
- bool have_error ;
1470
1471
bool noerr ;
1471
1472
ArrayType * arrtypmod ;
1472
1473
Datum datums [2 ];
@@ -1478,9 +1479,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1478
1479
if (elem .type != jpiNumeric )
1479
1480
elog (ERROR ,"invalid jsonpath item type for .decimal() precision" );
1480
1481
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 )
1484
1485
RETURN_ERROR (ereport (ERROR ,
1485
1486
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1486
1487
errmsg ("precision of jsonpath item method .%s() is out of range for type integer" ,
@@ -1492,9 +1493,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1492
1493
if (elem .type != jpiNumeric )
1493
1494
elog (ERROR ,"invalid jsonpath item type for .decimal() scale" );
1494
1495
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 )
1498
1499
RETURN_ERROR (ereport (ERROR ,
1499
1500
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1500
1501
errmsg ("scale of jsonpath item method .%s() is out of range for type integer" ,
@@ -1550,11 +1551,12 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1550
1551
1551
1552
if (jb -> type == jbvNumeric )
1552
1553
{
1553
- bool have_error ;
1554
1554
int32 val ;
1555
+ ErrorSaveContext escontext = {T_ErrorSaveContext };
1555
1556
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 )
1558
1560
RETURN_ERROR (ereport (ERROR ,
1559
1561
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1560
1562
errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type %s" ,
@@ -2149,11 +2151,11 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
2149
2151
}
2150
2152
else
2151
2153
{
2152
- bool error = false ;
2154
+ ErrorSaveContext escontext = { T_ErrorSaveContext } ;
2153
2155
2154
- res = func (lval -> val .numeric ,rval -> val .numeric ,& error );
2156
+ res = func (lval -> val .numeric ,rval -> val .numeric ,( Node * ) & escontext );
2155
2157
2156
- if (error )
2158
+ if (escontext . error_occurred )
2157
2159
return jperError ;
2158
2160
}
2159
2161
@@ -2433,17 +2435,17 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
2433
2435
if (jsp -> type != jpiDatetime && jsp -> type != jpiDate &&
2434
2436
jsp -> content .arg )
2435
2437
{
2436
- bool have_error ;
2438
+ ErrorSaveContext escontext = { T_ErrorSaveContext } ;
2437
2439
2438
2440
jspGetArg (jsp ,& elem );
2439
2441
2440
2442
if (elem .type != jpiNumeric )
2441
2443
elog (ERROR ,"invalid jsonpath item type for %s argument" ,
2442
2444
jspOperationName (jsp -> type ));
2443
2445
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 )
2447
2449
RETURN_ERROR (ereport (ERROR ,
2448
2450
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
2449
2451
errmsg ("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,
3462
3464
JsonValueList found = {0 };
3463
3465
JsonPathExecResult res = executeItem (cxt ,jsp ,jb ,& found );
3464
3466
Datum numeric_index ;
3465
- bool have_error = false ;
3467
+ ErrorSaveContext escontext = { T_ErrorSaveContext } ;
3466
3468
3467
3469
if (jperIsError (res ))
3468
3470
return res ;
@@ -3477,10 +3479,10 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
3477
3479
NumericGetDatum (jbv -> val .numeric ),
3478
3480
Int32GetDatum (0 ));
3479
3481
3480
- * index = numeric_int4_opt_error (DatumGetNumeric (numeric_index ),
3481
- & have_error );
3482
+ * index = numeric_int4_safe (DatumGetNumeric (numeric_index ),
3483
+ ( Node * ) & escontext );
3482
3484
3483
- if (have_error )
3485
+ if (escontext . error_occurred )
3484
3486
RETURN_ERROR (ereport (ERROR ,
3485
3487
(errcode (ERRCODE_INVALID_SQL_JSON_SUBSCRIPT ),
3486
3488
errmsg ("jsonpath array subscript is out of integer range" ))));