aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonpath_exec.c
diff options
context:
space:
mode:
authorÁlvaro Herrera <alvherre@alvh.no-ip.org>2024-12-14 12:55:00 +0100
committerÁlvaro Herrera <alvherre@alvh.no-ip.org>2024-12-14 12:55:00 +0100
commit62b7a9a7784eb8b3871368726fc3b8df17d87f32 (patch)
treead3c040ae5f4f92b56876d7f490708f2334d2e4e /src/backend/utils/adt/jsonpath_exec.c
parent7bc9a8bdd2d6f6da664572456f226c54e9c9e3dd (diff)
downloadpostgresql-62b7a9a7784eb8b3871368726fc3b8df17d87f32.tar.gz
postgresql-62b7a9a7784eb8b3871368726fc3b8df17d87f32.zip
Refactor some SQL/JSON error messages
Turn type names into "%s" specifiers to 1) avoid getting them translated and 2) reduce the total number of messages.
Diffstat (limited to 'src/backend/utils/adt/jsonpath_exec.c')
-rw-r--r--src/backend/utils/adt/jsonpath_exec.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c
index de35c8ce476..391c129ff88 100644
--- a/src/backend/utils/adt/jsonpath_exec.c
+++ b/src/backend/utils/adt/jsonpath_exec.c
@@ -1162,8 +1162,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
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)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
+ tmp, jspOperationName(jsp->type), "double precision"))));
if (isinf(val) || isnan(val))
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
@@ -1188,8 +1188,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
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)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
+ tmp, jspOperationName(jsp->type), "double precision"))));
if (isinf(val) || isnan(val))
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
@@ -1276,10 +1276,11 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (have_error)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type bigint",
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
DatumGetCString(DirectFunctionCall1(numeric_out,
NumericGetDatum(jb->val.numeric))),
- jspOperationName(jsp->type)))));
+ jspOperationName(jsp->type),
+ "bigint"))));
datum = Int64GetDatum(val);
res = jperOk;
@@ -1300,8 +1301,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || 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 bigint",
- tmp, jspOperationName(jsp->type)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
+ tmp, jspOperationName(jsp->type), "bigint"))));
res = jperOk;
}
@@ -1352,8 +1353,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || 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 boolean",
- tmp, jspOperationName(jsp->type)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
+ tmp, jspOperationName(jsp->type), "boolean"))));
ival = DatumGetInt32(datum);
if (ival == 0)
@@ -1372,8 +1373,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!parse_bool(tmp, &bval))
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type boolean",
- tmp, jspOperationName(jsp->type)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
+ tmp, jspOperationName(jsp->type), "boolean"))));
res = jperOk;
}
@@ -1434,8 +1435,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || 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 numeric",
- numstr, jspOperationName(jsp->type)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
+ numstr, jspOperationName(jsp->type), "numeric"))));
num = DatumGetNumeric(datum);
if (numeric_is_nan(num) || numeric_is_inf(num))
@@ -1523,8 +1524,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || 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 numeric",
- numstr, jspOperationName(jsp->type)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
+ numstr, jspOperationName(jsp->type), "numeric"))));
num = DatumGetNumeric(numdatum);
pfree(arrtypmod);
@@ -1556,10 +1557,10 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (have_error)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type integer",
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
DatumGetCString(DirectFunctionCall1(numeric_out,
NumericGetDatum(jb->val.numeric))),
- jspOperationName(jsp->type)))));
+ jspOperationName(jsp->type), "integer"))));
datum = Int32GetDatum(val);
res = jperOk;
@@ -1580,8 +1581,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || 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 integer",
- tmp, jspOperationName(jsp->type)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type %s",
+ tmp, jspOperationName(jsp->type), "integer"))));
res = jperOk;
}