Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b9a04a9

Browse files
committed
Improve error reporting for jsonpath .double() method
When jsonpath .double() method detects that numeric or string can't be converted to double precision, it throws an error. This commit makes these errors explicitly express the reason of failure. Discussion: https://postgr.es/m/CAPpHfdtqJtiSXkP7tOXez18NxhLUH_-75bL8%3DOce4Ki%2Bbv7V6Q%40mail.gmail.com Author: Alexander Korotkov Reviewed-by: Tom Lane Backpatch-through: 12
1 parent 763a0b6 commit b9a04a9

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/backend/utils/adt/jsonpath_exec.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
10551055
if (have_error)
10561056
RETURN_ERROR(ereport(ERROR,
10571057
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1058-
errmsg("jsonpath item method .%s() can only be applied to a numeric value",
1058+
errmsg("numeric argument of jsonpath item method .%s() is out of range for type double precision",
10591059
jspOperationName(jsp->type)))));
10601060
res = jperOk;
10611061
}
@@ -1076,7 +1076,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
10761076
if (have_error || isinf(val))
10771077
RETURN_ERROR(ereport(ERROR,
10781078
(errcode(ERRCODE_NON_NUMERIC_SQL_JSON_ITEM),
1079-
errmsg("jsonpath item method .%s() can only be applied to a numeric value",
1079+
errmsg("string argument of jsonpath item method .%s() is not a valid representation of a double precision number",
10801080
jspOperationName(jsp->type)))));
10811081

10821082
jb = &jbv;

src/test/regress/expected/jsonb_jsonpath.out

+5-3
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,9 @@ select jsonb_path_query('"1.23"', '$.double()');
14961496
(1 row)
14971497

14981498
select jsonb_path_query('"1.23aaa"', '$.double()');
1499-
ERROR: jsonpath item method .double() can only be applied to a numeric value
1499+
ERROR: string argument of jsonpath item method .double() is not a valid representation of a double precision number
1500+
select jsonb_path_query('1e1000', '$.double()');
1501+
ERROR: numeric argument of jsonpath item method .double() is out of range for type double precision
15001502
select jsonb_path_query('"nan"', '$.double()');
15011503
jsonb_path_query
15021504
------------------
@@ -1510,9 +1512,9 @@ select jsonb_path_query('"NaN"', '$.double()');
15101512
(1 row)
15111513

15121514
select jsonb_path_query('"inf"', '$.double()');
1513-
ERROR: jsonpath item method .double() can only be applied to a numeric value
1515+
ERROR: string argument of jsonpath item method .double() is not a valid representation of a double precision number
15141516
select jsonb_path_query('"-inf"', '$.double()');
1515-
ERROR: jsonpath item method .double() can only be applied to a numeric value
1517+
ERROR: string argument of jsonpath item method .double() is not a valid representation of a double precision number
15161518
select jsonb_path_query('"inf"', '$.double()', silent => true);
15171519
jsonb_path_query
15181520
------------------

src/test/regress/sql/jsonb_jsonpath.sql

+1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ select jsonb_path_query('{}', '$.double()', silent => true);
312312
select jsonb_path_query('1.23', '$.double()');
313313
select jsonb_path_query('"1.23"', '$.double()');
314314
select jsonb_path_query('"1.23aaa"', '$.double()');
315+
select jsonb_path_query('1e1000', '$.double()');
315316
select jsonb_path_query('"nan"', '$.double()');
316317
select jsonb_path_query('"NaN"', '$.double()');
317318
select jsonb_path_query('"inf"', '$.double()');

0 commit comments

Comments
 (0)