diff options
Diffstat (limited to 'src/backend/utils/adt/jsonpath_exec.c')
-rw-r--r-- | src/backend/utils/adt/jsonpath_exec.c | 86 |
1 files changed, 50 insertions, 36 deletions
diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c index 50fa724b728..3f30bc6222f 100644 --- a/src/backend/utils/adt/jsonpath_exec.c +++ b/src/backend/utils/adt/jsonpath_exec.c @@ -1051,10 +1051,15 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, tmp, (Node *) &escontext); - if (escontext.error_occurred || isinf(val) || isnan(val)) + if (escontext.error_occurred) + RETURN_ERROR(ereport(ERROR, + (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type double precision", + tmp, jspOperationName(jsp->type))))); + if (isinf(val) || isnan(val)) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("numeric argument of jsonpath item method .%s() is out of range for type double precision", + errmsg("NaN or Infinity is not allowed for jsonpath item method .%s()", jspOperationName(jsp->type))))); res = jperOk; } @@ -1072,10 +1077,15 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, tmp, (Node *) &escontext); - if (escontext.error_occurred || isinf(val) || isnan(val)) + if (escontext.error_occurred) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("string argument of jsonpath item method .%s() is not a valid representation of a double precision number", + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type double precision", + tmp, jspOperationName(jsp->type))))); + if (isinf(val) || isnan(val)) + RETURN_ERROR(ereport(ERROR, + (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), + errmsg("NaN or Infinity is not allowed for jsonpath item method .%s()", jspOperationName(jsp->type))))); jb = &jbv; @@ -1158,7 +1168,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, if (have_error) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("numeric argument of jsonpath item method .%s() is out of range for type bigint", + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type bigint", + DatumGetCString(DirectFunctionCall1(numeric_out, + NumericGetDatum(jb->val.numeric))), jspOperationName(jsp->type))))); datum = Int64GetDatum(val); @@ -1180,8 +1192,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, if (!noerr || escontext.error_occurred) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("string argument of jsonpath item method .%s() is not a valid representation of a big integer", - jspOperationName(jsp->type))))); + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type bigint", + tmp, jspOperationName(jsp->type))))); res = jperOk; } @@ -1232,8 +1244,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, if (!noerr || escontext.error_occurred) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("numeric argument of jsonpath item method .%s() is out of range for type boolean", - jspOperationName(jsp->type))))); + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type boolean", + tmp, jspOperationName(jsp->type))))); ival = DatumGetInt32(datum); if (ival == 0) @@ -1252,8 +1264,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, if (!parse_bool(tmp, &bval)) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("string argument of jsonpath item method .%s() is not a valid representation of a boolean", - jspOperationName(jsp->type))))); + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type boolean", + tmp, jspOperationName(jsp->type))))); res = jperOk; } @@ -1289,7 +1301,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, if (numeric_is_nan(num) || numeric_is_inf(num)) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("numeric argument of jsonpath item method .%s() is out of range for type decimal or number", + errmsg("NaN or Infinity is not allowed for jsonpath item method .%s()", jspOperationName(jsp->type))))); if (jsp->type == jpiDecimal) @@ -1314,14 +1326,14 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, if (!noerr || escontext.error_occurred) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("string argument of jsonpath item method .%s() is not a valid representation of a decimal or number", - jspOperationName(jsp->type))))); + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type numeric", + numstr, jspOperationName(jsp->type))))); num = DatumGetNumeric(datum); if (numeric_is_nan(num) || numeric_is_inf(num)) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("string argument of jsonpath item method .%s() is not a valid representation of a decimal or number", + errmsg("NaN or Infinity is not allowed for jsonpath item method .%s()", jspOperationName(jsp->type))))); res = jperOk; @@ -1403,8 +1415,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, if (!noerr || escontext.error_occurred) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("string argument of jsonpath item method .%s() is not a valid representation of a decimal or number", - jspOperationName(jsp->type))))); + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type numeric", + numstr, jspOperationName(jsp->type))))); num = DatumGetNumeric(numdatum); pfree(arrtypmod); @@ -1436,7 +1448,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, if (have_error) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("numeric argument of jsonpath item method .%s() is out of range for type integer", + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type integer", + DatumGetCString(DirectFunctionCall1(numeric_out, + NumericGetDatum(jb->val.numeric))), jspOperationName(jsp->type))))); datum = Int32GetDatum(val); @@ -1458,8 +1472,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, if (!noerr || escontext.error_occurred) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM), - errmsg("string argument of jsonpath item method .%s() is not a valid representation of an integer", - jspOperationName(jsp->type))))); + errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type integer", + tmp, jspOperationName(jsp->type))))); res = jperOk; } @@ -2373,8 +2387,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, if (jsp->type == jpiDatetime) RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION), - errmsg("datetime format is not recognized: \"%s\"", - text_to_cstring(datetime)), + errmsg("%s format is not recognized: \"%s\"", + "datetime", text_to_cstring(datetime)), errhint("Use a datetime template argument to specify the input data format.")))); else RETURN_ERROR(ereport(ERROR, @@ -2406,8 +2420,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, case TIMETZOID: RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION), - errmsg("date format is not recognized: \"%s\"", - text_to_cstring(datetime))))); + errmsg("%s format is not recognized: \"%s\"", + "date", text_to_cstring(datetime))))); break; case TIMESTAMPOID: value = DirectFunctionCall1(timestamp_date, @@ -2434,8 +2448,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, case DATEOID: RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION), - errmsg("time format is not recognized: \"%s\"", - text_to_cstring(datetime))))); + errmsg("%s format is not recognized: \"%s\"", + "time", text_to_cstring(datetime))))); break; case TIMEOID: /* Nothing to do for TIME */ break; @@ -2487,8 +2501,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, case TIMESTAMPOID: RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION), - errmsg("time_tz format is not recognized: \"%s\"", - text_to_cstring(datetime))))); + errmsg("%s format is not recognized: \"%s\"", + "time_tz", text_to_cstring(datetime))))); break; case TIMEOID: checkTimezoneIsUsedForCast(cxt->useTz, @@ -2538,8 +2552,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, case TIMETZOID: RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION), - errmsg("timestamp format is not recognized: \"%s\"", - text_to_cstring(datetime))))); + errmsg("%s format is not recognized: \"%s\"", + "timestamp", text_to_cstring(datetime))))); break; case TIMESTAMPOID: /* Nothing to do for TIMESTAMP */ break; @@ -2565,10 +2579,10 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, result = DatumGetTimestamp(value); AdjustTimestampForTypmod(&result, time_precision, (Node *) &escontext); - if (escontext.error_occurred) + if (escontext.error_occurred) /* should not happen */ RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION), - errmsg("numeric argument of jsonpath item method .%s() is out of range for type integer", + errmsg("time precision of jsonpath item method .%s() is invalid", jspOperationName(jsp->type))))); value = TimestampGetDatum(result); @@ -2594,8 +2608,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, case TIMETZOID: RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION), - errmsg("timestamp_tz format is not recognized: \"%s\"", - text_to_cstring(datetime))))); + errmsg("%s format is not recognized: \"%s\"", + "timestamp_tz", text_to_cstring(datetime))))); break; case TIMESTAMPOID: checkTimezoneIsUsedForCast(cxt->useTz, @@ -2621,10 +2635,10 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, result = DatumGetTimestampTz(value); AdjustTimestampForTypmod(&result, time_precision, (Node *) &escontext); - if (escontext.error_occurred) + if (escontext.error_occurred) /* should not happen */ RETURN_ERROR(ereport(ERROR, (errcode(ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION), - errmsg("numeric argument of jsonpath item method .%s() is out of range for type integer", + errmsg("time precision of jsonpath item method .%s() is invalid", jspOperationName(jsp->type))))); value = TimestampTzGetDatum(result); |