@@ -1051,10 +1051,15 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1051
1051
tmp ,
1052
1052
(Node * ) & escontext );
1053
1053
1054
- if (escontext .error_occurred || isinf (val ) || isnan (val ))
1054
+ if (escontext .error_occurred )
1055
+ RETURN_ERROR (ereport (ERROR ,
1056
+ (errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1057
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type double precision" ,
1058
+ tmp , jspOperationName (jsp -> type )))));
1059
+ if (isinf (val ) || isnan (val ))
1055
1060
RETURN_ERROR (ereport (ERROR ,
1056
1061
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1057
- errmsg ("numeric argument of jsonpath item method .%s() is out of range for type double precision " ,
1062
+ errmsg ("NaN or Infinity is not allowed for jsonpath item method .%s()" ,
1058
1063
jspOperationName (jsp -> type )))));
1059
1064
res = jperOk ;
1060
1065
}
@@ -1072,10 +1077,15 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1072
1077
tmp ,
1073
1078
(Node * ) & escontext );
1074
1079
1075
- if (escontext .error_occurred || isinf ( val ) || isnan ( val ) )
1080
+ if (escontext .error_occurred )
1076
1081
RETURN_ERROR (ereport (ERROR ,
1077
1082
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1078
- errmsg ("string argument of jsonpath item method .%s() is not a valid representation of a double precision number" ,
1083
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type double precision" ,
1084
+ tmp , jspOperationName (jsp -> type )))));
1085
+ if (isinf (val ) || isnan (val ))
1086
+ RETURN_ERROR (ereport (ERROR ,
1087
+ (errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1088
+ errmsg ("NaN or Infinity is not allowed for jsonpath item method .%s()" ,
1079
1089
jspOperationName (jsp -> type )))));
1080
1090
1081
1091
jb = & jbv ;
@@ -1158,7 +1168,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1158
1168
if (have_error )
1159
1169
RETURN_ERROR (ereport (ERROR ,
1160
1170
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1161
- errmsg ("numeric argument of jsonpath item method .%s() is out of range for type bigint" ,
1171
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type bigint" ,
1172
+ DatumGetCString (DirectFunctionCall1 (numeric_out ,
1173
+ NumericGetDatum (jb -> val .numeric ))),
1162
1174
jspOperationName (jsp -> type )))));
1163
1175
1164
1176
datum = Int64GetDatum (val );
@@ -1180,8 +1192,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1180
1192
if (!noerr || escontext .error_occurred )
1181
1193
RETURN_ERROR (ereport (ERROR ,
1182
1194
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1183
- errmsg ("string argument of jsonpath item method .%s() is not a valid representation of a big integer " ,
1184
- jspOperationName (jsp -> type )))));
1195
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type bigint " ,
1196
+ tmp , jspOperationName (jsp -> type )))));
1185
1197
res = jperOk ;
1186
1198
}
1187
1199
@@ -1232,8 +1244,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1232
1244
if (!noerr || escontext .error_occurred )
1233
1245
RETURN_ERROR (ereport (ERROR ,
1234
1246
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1235
- errmsg ("numeric argument of jsonpath item method .%s() is out of range for type boolean" ,
1236
- jspOperationName (jsp -> type )))));
1247
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type boolean" ,
1248
+ tmp , jspOperationName (jsp -> type )))));
1237
1249
1238
1250
ival = DatumGetInt32 (datum );
1239
1251
if (ival == 0 )
@@ -1252,8 +1264,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1252
1264
if (!parse_bool (tmp , & bval ))
1253
1265
RETURN_ERROR (ereport (ERROR ,
1254
1266
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1255
- errmsg ("string argument of jsonpath item method .%s() is not a valid representation of a boolean" ,
1256
- jspOperationName (jsp -> type )))));
1267
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type boolean" ,
1268
+ tmp , jspOperationName (jsp -> type )))));
1257
1269
1258
1270
res = jperOk ;
1259
1271
}
@@ -1289,7 +1301,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1289
1301
if (numeric_is_nan (num ) || numeric_is_inf (num ))
1290
1302
RETURN_ERROR (ereport (ERROR ,
1291
1303
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1292
- errmsg ("numeric argument of jsonpath item method .%s() is out of range for type decimal or number " ,
1304
+ errmsg ("NaN or Infinity is not allowed for jsonpath item method .%s()" ,
1293
1305
jspOperationName (jsp -> type )))));
1294
1306
1295
1307
if (jsp -> type == jpiDecimal )
@@ -1314,14 +1326,14 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1314
1326
if (!noerr || escontext .error_occurred )
1315
1327
RETURN_ERROR (ereport (ERROR ,
1316
1328
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1317
- errmsg ("string argument of jsonpath item method .%s() is not a valid representation of a decimal or number " ,
1318
- jspOperationName (jsp -> type )))));
1329
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type numeric " ,
1330
+ numstr , jspOperationName (jsp -> type )))));
1319
1331
1320
1332
num = DatumGetNumeric (datum );
1321
1333
if (numeric_is_nan (num ) || numeric_is_inf (num ))
1322
1334
RETURN_ERROR (ereport (ERROR ,
1323
1335
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1324
- errmsg ("string argument of jsonpath item method .%s() is not a valid representation of a decimal or number " ,
1336
+ errmsg ("NaN or Infinity is not allowed for jsonpath item method .%s()" ,
1325
1337
jspOperationName (jsp -> type )))));
1326
1338
1327
1339
res = jperOk ;
@@ -1403,8 +1415,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1403
1415
if (!noerr || escontext .error_occurred )
1404
1416
RETURN_ERROR (ereport (ERROR ,
1405
1417
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1406
- errmsg ("string argument of jsonpath item method .%s() is not a valid representation of a decimal or number " ,
1407
- jspOperationName (jsp -> type )))));
1418
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type numeric " ,
1419
+ numstr , jspOperationName (jsp -> type )))));
1408
1420
1409
1421
num = DatumGetNumeric (numdatum );
1410
1422
pfree (arrtypmod );
@@ -1436,7 +1448,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1436
1448
if (have_error )
1437
1449
RETURN_ERROR (ereport (ERROR ,
1438
1450
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1439
- errmsg ("numeric argument of jsonpath item method .%s() is out of range for type integer" ,
1451
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type integer" ,
1452
+ DatumGetCString (DirectFunctionCall1 (numeric_out ,
1453
+ NumericGetDatum (jb -> val .numeric ))),
1440
1454
jspOperationName (jsp -> type )))));
1441
1455
1442
1456
datum = Int32GetDatum (val );
@@ -1458,8 +1472,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1458
1472
if (!noerr || escontext .error_occurred )
1459
1473
RETURN_ERROR (ereport (ERROR ,
1460
1474
(errcode (ERRCODE_NON_NUMERIC_SQL_JSON_ITEM ),
1461
- errmsg ("string argument of jsonpath item method .%s() is not a valid representation of an integer" ,
1462
- jspOperationName (jsp -> type )))));
1475
+ errmsg ("argument \"%s\" of jsonpath item method .%s() is invalid for type integer" ,
1476
+ tmp , jspOperationName (jsp -> type )))));
1463
1477
res = jperOk ;
1464
1478
}
1465
1479
@@ -2373,8 +2387,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
2373
2387
if (jsp -> type == jpiDatetime )
2374
2388
RETURN_ERROR (ereport (ERROR ,
2375
2389
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
2376
- errmsg ("datetime format is not recognized: \"%s\"" ,
2377
- text_to_cstring (datetime )),
2390
+ errmsg ("%s format is not recognized: \"%s\"" ,
2391
+ "datetime" , text_to_cstring (datetime )),
2378
2392
errhint ("Use a datetime template argument to specify the input data format." ))));
2379
2393
else
2380
2394
RETURN_ERROR (ereport (ERROR ,
@@ -2406,8 +2420,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
2406
2420
case TIMETZOID :
2407
2421
RETURN_ERROR (ereport (ERROR ,
2408
2422
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
2409
- errmsg ("date format is not recognized: \"%s\"" ,
2410
- text_to_cstring (datetime )))));
2423
+ errmsg ("%s format is not recognized: \"%s\"" ,
2424
+ "date" , text_to_cstring (datetime )))));
2411
2425
break ;
2412
2426
case TIMESTAMPOID :
2413
2427
value = DirectFunctionCall1 (timestamp_date ,
@@ -2434,8 +2448,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
2434
2448
case DATEOID :
2435
2449
RETURN_ERROR (ereport (ERROR ,
2436
2450
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
2437
- errmsg ("time format is not recognized: \"%s\"" ,
2438
- text_to_cstring (datetime )))));
2451
+ errmsg ("%s format is not recognized: \"%s\"" ,
2452
+ "time" , text_to_cstring (datetime )))));
2439
2453
break ;
2440
2454
case TIMEOID : /* Nothing to do for TIME */
2441
2455
break ;
@@ -2487,8 +2501,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
2487
2501
case TIMESTAMPOID :
2488
2502
RETURN_ERROR (ereport (ERROR ,
2489
2503
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
2490
- errmsg ("time_tz format is not recognized: \"%s\"" ,
2491
- text_to_cstring (datetime )))));
2504
+ errmsg ("%s format is not recognized: \"%s\"" ,
2505
+ "time_tz" , text_to_cstring (datetime )))));
2492
2506
break ;
2493
2507
case TIMEOID :
2494
2508
checkTimezoneIsUsedForCast (cxt -> useTz ,
@@ -2538,8 +2552,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
2538
2552
case TIMETZOID :
2539
2553
RETURN_ERROR (ereport (ERROR ,
2540
2554
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
2541
- errmsg ("timestamp format is not recognized: \"%s\"" ,
2542
- text_to_cstring (datetime )))));
2555
+ errmsg ("%s format is not recognized: \"%s\"" ,
2556
+ "timestamp" , text_to_cstring (datetime )))));
2543
2557
break ;
2544
2558
case TIMESTAMPOID : /* Nothing to do for TIMESTAMP */
2545
2559
break ;
@@ -2565,10 +2579,10 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
2565
2579
result = DatumGetTimestamp (value );
2566
2580
AdjustTimestampForTypmod (& result , time_precision ,
2567
2581
(Node * ) & escontext );
2568
- if (escontext .error_occurred )
2582
+ if (escontext .error_occurred ) /* should not happen */
2569
2583
RETURN_ERROR (ereport (ERROR ,
2570
2584
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
2571
- errmsg ("numeric argument of jsonpath item method .%s() is out of range for type integer " ,
2585
+ errmsg ("time precision of jsonpath item method .%s() is invalid " ,
2572
2586
jspOperationName (jsp -> type )))));
2573
2587
value = TimestampGetDatum (result );
2574
2588
@@ -2594,8 +2608,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
2594
2608
case TIMETZOID :
2595
2609
RETURN_ERROR (ereport (ERROR ,
2596
2610
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
2597
- errmsg ("timestamp_tz format is not recognized: \"%s\"" ,
2598
- text_to_cstring (datetime )))));
2611
+ errmsg ("%s format is not recognized: \"%s\"" ,
2612
+ "timestamp_tz" , text_to_cstring (datetime )))));
2599
2613
break ;
2600
2614
case TIMESTAMPOID :
2601
2615
checkTimezoneIsUsedForCast (cxt -> useTz ,
@@ -2621,10 +2635,10 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
2621
2635
result = DatumGetTimestampTz (value );
2622
2636
AdjustTimestampForTypmod (& result , time_precision ,
2623
2637
(Node * ) & escontext );
2624
- if (escontext .error_occurred )
2638
+ if (escontext .error_occurred ) /* should not happen */
2625
2639
RETURN_ERROR (ereport (ERROR ,
2626
2640
(errcode (ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION ),
2627
- errmsg ("numeric argument of jsonpath item method .%s() is out of range for type integer " ,
2641
+ errmsg ("time precision of jsonpath item method .%s() is invalid " ,
2628
2642
jspOperationName (jsp -> type )))));
2629
2643
value = TimestampTzGetDatum (result );
2630
2644
0 commit comments