v1-0004-Show-input-value-in-the-error-message-of-various-.patch
application/octet-stream
Filename: v1-0004-Show-input-value-in-the-error-message-of-various-.patch
Type: application/octet-stream
Part: 3
Message:
Re: More new SQL/JSON item methods
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v1-0004
Subject: Show input value in the error message of various jsonpath item methods.
| File | + | − |
|---|---|---|
| src/backend/utils/adt/jsonpath_exec.c | 26 | 22 |
| src/test/regress/expected/jsonb_jsonpath.out | 33 | 33 |
From ba7f670d145b22810a744dd3b5eac72f304070ea Mon Sep 17 00:00:00 2001
From: Jeevan Chalke <jeevan.chalke@enterprisedb.com>
Date: Fri, 2 Feb 2024 09:51:37 +0530
Subject: [PATCH v1 4/4] Show input value in the error message of various
jsonpath item methods.
Jeevan Chalke, per discussion with Kyotaro Horiguchi and Tom Lane.
Discussion: https://www.postgresql.org/message-id/flat/CAM2+6=XjTyqrrqHAOj80r0wVQxJSxc0iyib9bPC55uFO9VKatg@mail.gmail.com
---
src/backend/utils/adt/jsonpath_exec.c | 48 ++++++++++----------
src/test/regress/expected/jsonb_jsonpath.out | 66 ++++++++++++++--------------
2 files changed, 59 insertions(+), 55 deletions(-)
diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c
index 8bb1017..32fb02a 100644
--- a/src/backend/utils/adt/jsonpath_exec.c
+++ b/src/backend/utils/adt/jsonpath_exec.c
@@ -1052,8 +1052,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (escontext.error_occurred)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid for type double precision",
- jspOperationName(jsp->type)))));
+ 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),
@@ -1078,8 +1078,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (escontext.error_occurred)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid for type double precision",
- jspOperationName(jsp->type)))));
+ 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),
@@ -1166,7 +1166,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (have_error)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid 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);
@@ -1188,8 +1190,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || escontext.error_occurred)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid for type bigint",
- jspOperationName(jsp->type)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type bigint",
+ tmp, jspOperationName(jsp->type)))));
res = jperOk;
}
@@ -1240,8 +1242,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || escontext.error_occurred)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid 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)
@@ -1260,8 +1262,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!parse_bool(tmp, &bval))
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid for type boolean",
- jspOperationName(jsp->type)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type boolean",
+ tmp, jspOperationName(jsp->type)))));
res = jperOk;
}
@@ -1322,8 +1324,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || escontext.error_occurred)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid for type numeric",
- 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))
@@ -1411,8 +1413,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || escontext.error_occurred)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid for type numeric",
- 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);
@@ -1444,7 +1446,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (have_error)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid 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);
@@ -1466,8 +1470,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!noerr || escontext.error_occurred)
RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
- errmsg("argument of jsonpath item method .%s() is invalid for type integer",
- jspOperationName(jsp->type)))));
+ errmsg("argument \"%s\" of jsonpath item method .%s() is invalid for type integer",
+ tmp, jspOperationName(jsp->type)))));
res = jperOk;
}
@@ -2560,10 +2564,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("argument of jsonpath item method .%s() is invalid for type integer",
+ errmsg("time precision of jsonpath item method .%s() is invalid",
jspOperationName(jsp->type)))));
value = TimestampGetDatum(result);
@@ -2612,10 +2616,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("argument of jsonpath item method .%s() is invalid for type integer",
+ errmsg("time precision of jsonpath item method .%s() is invalid",
jspOperationName(jsp->type)))));
value = TimestampTzGetDatum(result);
diff --git a/src/test/regress/expected/jsonb_jsonpath.out b/src/test/regress/expected/jsonb_jsonpath.out
index 5fc9fea..4eac9c9 100644
--- a/src/test/regress/expected/jsonb_jsonpath.out
+++ b/src/test/regress/expected/jsonb_jsonpath.out
@@ -1496,9 +1496,9 @@ select jsonb_path_query('"1.23"', '$.double()');
(1 row)
select jsonb_path_query('"1.23aaa"', '$.double()');
-ERROR: argument of jsonpath item method .double() is invalid for type double precision
+ERROR: argument "1.23aaa" of jsonpath item method .double() is invalid for type double precision
select jsonb_path_query('1e1000', '$.double()');
-ERROR: argument of jsonpath item method .double() is invalid for type double precision
+ERROR: argument "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" of jsonpath item method .double() is invalid for type double precision
select jsonb_path_query('"nan"', '$.double()');
ERROR: NaN or Infinity is not allowed for jsonpath item method .double()
select jsonb_path_query('"NaN"', '$.double()');
@@ -1767,19 +1767,19 @@ select jsonb_path_query('{}', '$.bigint()', silent => true);
(0 rows)
select jsonb_path_query('"1.23"', '$.bigint()');
-ERROR: argument of jsonpath item method .bigint() is invalid for type bigint
+ERROR: argument "1.23" of jsonpath item method .bigint() is invalid for type bigint
select jsonb_path_query('"1.23aaa"', '$.bigint()');
-ERROR: argument of jsonpath item method .bigint() is invalid for type bigint
+ERROR: argument "1.23aaa" of jsonpath item method .bigint() is invalid for type bigint
select jsonb_path_query('1e1000', '$.bigint()');
-ERROR: argument of jsonpath item method .bigint() is invalid for type bigint
+ERROR: argument "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" of jsonpath item method .bigint() is invalid for type bigint
select jsonb_path_query('"nan"', '$.bigint()');
-ERROR: argument of jsonpath item method .bigint() is invalid for type bigint
+ERROR: argument "nan" of jsonpath item method .bigint() is invalid for type bigint
select jsonb_path_query('"NaN"', '$.bigint()');
-ERROR: argument of jsonpath item method .bigint() is invalid for type bigint
+ERROR: argument "NaN" of jsonpath item method .bigint() is invalid for type bigint
select jsonb_path_query('"inf"', '$.bigint()');
-ERROR: argument of jsonpath item method .bigint() is invalid for type bigint
+ERROR: argument "inf" of jsonpath item method .bigint() is invalid for type bigint
select jsonb_path_query('"-inf"', '$.bigint()');
-ERROR: argument of jsonpath item method .bigint() is invalid for type bigint
+ERROR: argument "-inf" of jsonpath item method .bigint() is invalid for type bigint
select jsonb_path_query('"inf"', '$.bigint()', silent => true);
jsonb_path_query
------------------
@@ -1827,9 +1827,9 @@ select jsonb_path_query('"1234567890123"', '$.bigint()');
(1 row)
select jsonb_path_query('12345678901234567890', '$.bigint()');
-ERROR: argument of jsonpath item method .bigint() is invalid for type bigint
+ERROR: argument "12345678901234567890" of jsonpath item method .bigint() is invalid for type bigint
select jsonb_path_query('"12345678901234567890"', '$.bigint()');
-ERROR: argument of jsonpath item method .bigint() is invalid for type bigint
+ERROR: argument "12345678901234567890" of jsonpath item method .bigint() is invalid for type bigint
select jsonb_path_query('"+123"', '$.bigint()');
jsonb_path_query
------------------
@@ -1882,21 +1882,21 @@ select jsonb_path_query('{}', '$.boolean()', silent => true);
(0 rows)
select jsonb_path_query('1.23', '$.boolean()');
-ERROR: argument of jsonpath item method .boolean() is invalid for type boolean
+ERROR: argument "1.23" of jsonpath item method .boolean() is invalid for type boolean
select jsonb_path_query('"1.23"', '$.boolean()');
-ERROR: argument of jsonpath item method .boolean() is invalid for type boolean
+ERROR: argument "1.23" of jsonpath item method .boolean() is invalid for type boolean
select jsonb_path_query('"1.23aaa"', '$.boolean()');
-ERROR: argument of jsonpath item method .boolean() is invalid for type boolean
+ERROR: argument "1.23aaa" of jsonpath item method .boolean() is invalid for type boolean
select jsonb_path_query('1e1000', '$.boolean()');
-ERROR: argument of jsonpath item method .boolean() is invalid for type boolean
+ERROR: argument "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" of jsonpath item method .boolean() is invalid for type boolean
select jsonb_path_query('"nan"', '$.boolean()');
-ERROR: argument of jsonpath item method .boolean() is invalid for type boolean
+ERROR: argument "nan" of jsonpath item method .boolean() is invalid for type boolean
select jsonb_path_query('"NaN"', '$.boolean()');
-ERROR: argument of jsonpath item method .boolean() is invalid for type boolean
+ERROR: argument "NaN" of jsonpath item method .boolean() is invalid for type boolean
select jsonb_path_query('"inf"', '$.boolean()');
-ERROR: argument of jsonpath item method .boolean() is invalid for type boolean
+ERROR: argument "inf" of jsonpath item method .boolean() is invalid for type boolean
select jsonb_path_query('"-inf"', '$.boolean()');
-ERROR: argument of jsonpath item method .boolean() is invalid for type boolean
+ERROR: argument "-inf" of jsonpath item method .boolean() is invalid for type boolean
select jsonb_path_query('"inf"', '$.boolean()', silent => true);
jsonb_path_query
------------------
@@ -1908,7 +1908,7 @@ select jsonb_path_query('"-inf"', '$.boolean()', silent => true);
(0 rows)
select jsonb_path_query('"100"', '$.boolean()');
-ERROR: argument of jsonpath item method .boolean() is invalid for type boolean
+ERROR: argument "100" of jsonpath item method .boolean() is invalid for type boolean
select jsonb_path_query('true', '$.boolean()');
jsonb_path_query
------------------
@@ -2144,7 +2144,7 @@ select jsonb_path_query('"1.23"', '$.decimal()');
(1 row)
select jsonb_path_query('"1.23aaa"', '$.decimal()');
-ERROR: argument of jsonpath item method .decimal() is invalid for type numeric
+ERROR: argument "1.23aaa" of jsonpath item method .decimal() is invalid for type numeric
select jsonb_path_query('1e1000', '$.decimal()');
jsonb_path_query
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -2224,7 +2224,7 @@ select jsonb_path_query('12345.678', '$.decimal(6, 1)');
(1 row)
select jsonb_path_query('12345.678', '$.decimal(6, 2)');
-ERROR: argument of jsonpath item method .decimal() is invalid for type numeric
+ERROR: argument "12345.678" of jsonpath item method .decimal() is invalid for type numeric
select jsonb_path_query('1234.5678', '$.decimal(6, 2)');
jsonb_path_query
------------------
@@ -2232,7 +2232,7 @@ select jsonb_path_query('1234.5678', '$.decimal(6, 2)');
(1 row)
select jsonb_path_query('12345.678', '$.decimal(4, 6)');
-ERROR: argument of jsonpath item method .decimal() is invalid for type numeric
+ERROR: argument "12345.678" of jsonpath item method .decimal() is invalid for type numeric
select jsonb_path_query('12345.678', '$.decimal(0, 6)');
ERROR: NUMERIC precision 0 must be between 1 and 1000
select jsonb_path_query('12345.678', '$.decimal(1001, 6)');
@@ -2318,19 +2318,19 @@ select jsonb_path_query('{}', '$.integer()', silent => true);
(0 rows)
select jsonb_path_query('"1.23"', '$.integer()');
-ERROR: argument of jsonpath item method .integer() is invalid for type integer
+ERROR: argument "1.23" of jsonpath item method .integer() is invalid for type integer
select jsonb_path_query('"1.23aaa"', '$.integer()');
-ERROR: argument of jsonpath item method .integer() is invalid for type integer
+ERROR: argument "1.23aaa" of jsonpath item method .integer() is invalid for type integer
select jsonb_path_query('1e1000', '$.integer()');
-ERROR: argument of jsonpath item method .integer() is invalid for type integer
+ERROR: argument "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" of jsonpath item method .integer() is invalid for type integer
select jsonb_path_query('"nan"', '$.integer()');
-ERROR: argument of jsonpath item method .integer() is invalid for type integer
+ERROR: argument "nan" of jsonpath item method .integer() is invalid for type integer
select jsonb_path_query('"NaN"', '$.integer()');
-ERROR: argument of jsonpath item method .integer() is invalid for type integer
+ERROR: argument "NaN" of jsonpath item method .integer() is invalid for type integer
select jsonb_path_query('"inf"', '$.integer()');
-ERROR: argument of jsonpath item method .integer() is invalid for type integer
+ERROR: argument "inf" of jsonpath item method .integer() is invalid for type integer
select jsonb_path_query('"-inf"', '$.integer()');
-ERROR: argument of jsonpath item method .integer() is invalid for type integer
+ERROR: argument "-inf" of jsonpath item method .integer() is invalid for type integer
select jsonb_path_query('"inf"', '$.integer()', silent => true);
jsonb_path_query
------------------
@@ -2366,9 +2366,9 @@ select jsonb_path_query('1.83', '$.integer()');
(1 row)
select jsonb_path_query('12345678901', '$.integer()');
-ERROR: argument of jsonpath item method .integer() is invalid for type integer
+ERROR: argument "12345678901" of jsonpath item method .integer() is invalid for type integer
select jsonb_path_query('"12345678901"', '$.integer()');
-ERROR: argument of jsonpath item method .integer() is invalid for type integer
+ERROR: argument "12345678901" of jsonpath item method .integer() is invalid for type integer
select jsonb_path_query('"+123"', '$.integer()');
jsonb_path_query
------------------
@@ -2440,7 +2440,7 @@ select jsonb_path_query('"1.23"', '$.number()');
(1 row)
select jsonb_path_query('"1.23aaa"', '$.number()');
-ERROR: argument of jsonpath item method .number() is invalid for type numeric
+ERROR: argument "1.23aaa" of jsonpath item method .number() is invalid for type numeric
select jsonb_path_query('1e1000', '$.number()');
jsonb_path_query
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--
1.8.3.1