Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4246a97

Browse files
committed
Switch some numeric-related functions to use soft error reporting
This commit changes some functions related to the data type numeric touse the soft error reporting rather than a custom boolean flag (called"have_error") that callers of these functions could rely on to bypassthe generation of ERROR reports, letting the callers do their own errorhandling (timestamp, jsonpath and numeric_to_char() require them).This results in the removal of some boilerplate code that was requiredto handle both the ereport() and the "have_error" code paths bypassingereport(), unifying everything under the soft error reporting facility.While on it, some duplicated error messages are removed. The functionupgraded in this commit were suffixed with "_opt_error" in their names.They are renamed to "_safe" instead.This change relies ond9f7f5d, that has introduced the soft errorreporting infrastructure.Author: Amul Sul <sulamul@gmail.com>Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>Discussion:https://postgr.es/m/CAAJ_b96No5h5tRuR+KhcC44YcYUCw8WAHuLoqqyyop8_k3+JDQ@mail.gmail.com
1 parentae45312 commit4246a97

File tree

5 files changed

+152
-250
lines changed

5 files changed

+152
-250
lines changed

‎src/backend/utils/adt/formatting.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6389,12 +6389,12 @@ numeric_to_char(PG_FUNCTION_ARGS)
63896389
if (IS_ROMAN(&Num))
63906390
{
63916391
int32intvalue;
6392-
boolerr;
6392+
ErrorSaveContextescontext= {T_ErrorSaveContext};
63936393

63946394
/* Round and convert to int */
6395-
intvalue=numeric_int4_opt_error(value,&err);
6395+
intvalue=numeric_int4_safe(value,(Node*)&escontext);
63966396
/* On overflow, just use PG_INT32_MAX; int_to_roman will cope */
6397-
if (err)
6397+
if (escontext.error_occurred)
63986398
intvalue=PG_INT32_MAX;
63996399
numstr=int_to_roman(intvalue);
64006400
}

‎src/backend/utils/adt/jsonpath_exec.c‎

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ typedef JsonPathBool (*JsonPathPredicateCallback) (JsonPathItem *jsp,
252252
JsonbValue*larg,
253253
JsonbValue*rarg,
254254
void*param);
255-
typedefNumeric (*BinaryArithmFunc) (Numericnum1,Numericnum2,bool*error);
255+
typedefNumeric (*BinaryArithmFunc) (Numericnum1,Numericnum2,
256+
Node*escontext);
256257

257258
staticJsonPathExecResultexecuteJsonPath(JsonPath*path,void*vars,
258259
JsonPathGetVarCallbackgetVar,
@@ -808,23 +809,23 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
808809

809810
casejpiAdd:
810811
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
811-
numeric_add_opt_error,found);
812+
numeric_add_safe,found);
812813

813814
casejpiSub:
814815
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
815-
numeric_sub_opt_error,found);
816+
numeric_sub_safe,found);
816817

817818
casejpiMul:
818819
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
819-
numeric_mul_opt_error,found);
820+
numeric_mul_safe,found);
820821

821822
casejpiDiv:
822823
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
823-
numeric_div_opt_error,found);
824+
numeric_div_safe,found);
824825

825826
casejpiMod:
826827
returnexecuteBinaryArithmExpr(cxt,jsp,jb,
827-
numeric_mod_opt_error,found);
828+
numeric_mod_safe,found);
828829

829830
casejpiPlus:
830831
returnexecuteUnaryArithmExpr(cxt,jsp,jb,NULL,found);
@@ -1269,11 +1270,12 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
12691270

12701271
if (jb->type==jbvNumeric)
12711272
{
1272-
boolhave_error;
1273+
ErrorSaveContextescontext= {T_ErrorSaveContext};
12731274
int64val;
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)
12771279
RETURN_ERROR(ereport(ERROR,
12781280
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
12791281
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
@@ -1466,7 +1468,6 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
14661468
Datumdtypmod;
14671469
int32precision;
14681470
int32scale=0;
1469-
boolhave_error;
14701471
boolnoerr;
14711472
ArrayType*arrtypmod;
14721473
Datumdatums[2];
@@ -1478,9 +1479,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
14781479
if (elem.type!=jpiNumeric)
14791480
elog(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)
14841485
RETURN_ERROR(ereport(ERROR,
14851486
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
14861487
errmsg("precision of jsonpath item method .%s() is out of range for type integer",
@@ -1492,9 +1493,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
14921493
if (elem.type!=jpiNumeric)
14931494
elog(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)
14981499
RETURN_ERROR(ereport(ERROR,
14991500
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
15001501
errmsg("scale of jsonpath item method .%s() is out of range for type integer",
@@ -1550,11 +1551,12 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
15501551

15511552
if (jb->type==jbvNumeric)
15521553
{
1553-
boolhave_error;
15541554
int32val;
1555+
ErrorSaveContextescontext= {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)
15581560
RETURN_ERROR(ereport(ERROR,
15591561
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
15601562
errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
@@ -2149,11 +2151,11 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
21492151
}
21502152
else
21512153
{
2152-
boolerror= false;
2154+
ErrorSaveContextescontext= {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)
21572159
returnjperError;
21582160
}
21592161

@@ -2433,17 +2435,17 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
24332435
if (jsp->type!=jpiDatetime&&jsp->type!=jpiDate&&
24342436
jsp->content.arg)
24352437
{
2436-
boolhave_error;
2438+
ErrorSaveContextescontext= {T_ErrorSaveContext};
24372439

24382440
jspGetArg(jsp,&elem);
24392441

24402442
if (elem.type!=jpiNumeric)
24412443
elog(ERROR,"invalid jsonpath item type for %s argument",
24422444
jspOperationName(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)
24472449
RETURN_ERROR(ereport(ERROR,
24482450
(errcode(ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION),
24492451
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,
34623464
JsonValueListfound= {0};
34633465
JsonPathExecResultres=executeItem(cxt,jsp,jb,&found);
34643466
Datumnumeric_index;
3465-
boolhave_error= false;
3467+
ErrorSaveContextescontext= {T_ErrorSaveContext};
34663468

34673469
if (jperIsError(res))
34683470
returnres;
@@ -3477,10 +3479,10 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
34773479
NumericGetDatum(jbv->val.numeric),
34783480
Int32GetDatum(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)
34843486
RETURN_ERROR(ereport(ERROR,
34853487
(errcode(ERRCODE_INVALID_SQL_JSON_SUBSCRIPT),
34863488
errmsg("jsonpath array subscript is out of integer range"))));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp