77
77
#include "utils/varlena.h"
78
78
79
79
80
- /* Standard error message for SQL/JSON errors */
81
- #define ERRMSG_JSON_ARRAY_NOT_FOUND "SQL/JSON array not found"
82
- #define ERRMSG_JSON_OBJECT_NOT_FOUND "SQL/JSON object not found"
83
- #define ERRMSG_JSON_MEMBER_NOT_FOUND "SQL/JSON member not found"
84
- #define ERRMSG_JSON_NUMBER_NOT_FOUND "SQL/JSON number not found"
85
- #define ERRMSG_JSON_SCALAR_REQUIRED "SQL/JSON scalar required"
86
- #define ERRMSG_SINGLETON_JSON_ITEM_REQUIRED "singleton SQL/JSON item required"
87
- #define ERRMSG_NON_NUMERIC_JSON_ITEM "non-numeric SQL/JSON item"
88
- #define ERRMSG_INVALID_JSON_SUBSCRIPT "invalid SQL/JSON subscript"
89
-
90
80
/*
91
81
* Represents "base object" and it's "id" for .keyvalue() evaluation.
92
82
*/
@@ -349,8 +339,7 @@ jsonb_path_match(PG_FUNCTION_ARGS)
349
339
if (!silent )
350
340
ereport (ERROR ,
351
341
(errcode (ERRCODE_SINGLETON_JSON_ITEM_REQUIRED ),
352
- errmsg (ERRMSG_SINGLETON_JSON_ITEM_REQUIRED ),
353
- errdetail ("expression should return a singleton boolean" )));
342
+ errmsg ("single boolean result is expected" )));
354
343
355
344
PG_RETURN_NULL ();
356
345
}
@@ -498,8 +487,8 @@ executeJsonPath(JsonPath *path, Jsonb *vars, Jsonb *json, bool throwErrors,
498
487
{
499
488
ereport (ERROR ,
500
489
(errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
501
- errmsg ("jsonb containing jsonpath variables "
502
- "is not an object" )));
490
+ errmsg ("\"vars\" argument is not an object" ),
491
+ errdetail ( "Jsonpath parameters should be encoded as key-value pairs of \"vars\" object. " )));
503
492
}
504
493
505
494
cxt .vars = vars ;
@@ -608,24 +597,16 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
608
597
}
609
598
else if (!jspIgnoreStructuralErrors (cxt ))
610
599
{
611
- StringInfoData keybuf ;
612
- char * keystr ;
613
-
614
600
Assert (found );
615
601
616
602
if (!jspThrowErrors (cxt ))
617
603
return jperError ;
618
604
619
- initStringInfo (& keybuf );
620
-
621
- keystr = pnstrdup (key .val .string .val , key .val .string .len );
622
- escape_json (& keybuf , keystr );
623
-
624
605
ereport (ERROR ,
625
606
(errcode (ERRCODE_JSON_MEMBER_NOT_FOUND ), \
626
- errmsg (ERRMSG_JSON_MEMBER_NOT_FOUND ) ,
627
- errdetail ( "JSON object does not contain key %s" ,
628
- keybuf . data )));
607
+ errmsg ("JSON object does not contain key \"%s\"" ,
608
+ pnstrdup ( key . val . string . val ,
609
+ key . val . string . len ) )));
629
610
}
630
611
}
631
612
else if (unwrap && JsonbType (jb ) == jbvArray )
@@ -635,9 +616,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
635
616
Assert (found );
636
617
RETURN_ERROR (ereport (ERROR ,
637
618
(errcode (ERRCODE_JSON_MEMBER_NOT_FOUND ),
638
- errmsg (ERRMSG_JSON_MEMBER_NOT_FOUND ),
639
- errdetail ("jsonpath member accessor can "
640
- "only be applied to an object" ))));
619
+ errmsg ("jsonpath member accessor can only be applied to an object" ))));
641
620
}
642
621
break ;
643
622
@@ -666,9 +645,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
666
645
else if (!jspIgnoreStructuralErrors (cxt ))
667
646
RETURN_ERROR (ereport (ERROR ,
668
647
(errcode (ERRCODE_JSON_ARRAY_NOT_FOUND ),
669
- errmsg (ERRMSG_JSON_ARRAY_NOT_FOUND ),
670
- errdetail ("jsonpath wildcard array accessor "
671
- "can only be applied to an array" ))));
648
+ errmsg ("jsonpath wildcard array accessor can only be applied to an array" ))));
672
649
break ;
673
650
674
651
case jpiIndexArray :
@@ -716,9 +693,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
716
693
index_to >= size ))
717
694
RETURN_ERROR (ereport (ERROR ,
718
695
(errcode (ERRCODE_INVALID_JSON_SUBSCRIPT ),
719
- errmsg (ERRMSG_INVALID_JSON_SUBSCRIPT ),
720
- errdetail ("jsonpath array subscript is "
721
- "out of bounds" ))));
696
+ errmsg ("jsonpath array subscript is out of bounds" ))));
722
697
723
698
if (index_from < 0 )
724
699
index_from = 0 ;
@@ -775,9 +750,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
775
750
{
776
751
RETURN_ERROR (ereport (ERROR ,
777
752
(errcode (ERRCODE_JSON_ARRAY_NOT_FOUND ),
778
- errmsg (ERRMSG_JSON_ARRAY_NOT_FOUND ),
779
- errdetail ("jsonpath array accessor can "
780
- "only be applied to an array" ))));
753
+ errmsg ("jsonpath array accessor can only be applied to an array" ))));
781
754
}
782
755
break ;
783
756
@@ -789,8 +762,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
789
762
bool hasNext = jspGetNext (jsp , & elem );
790
763
791
764
if (cxt -> innermostArraySize < 0 )
792
- elog (ERROR , "evaluating jsonpath LAST outside of "
793
- "array subscript" );
765
+ elog (ERROR , "evaluating jsonpath LAST outside of array subscript" );
794
766
795
767
if (!hasNext && !found )
796
768
{
@@ -832,9 +804,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
832
804
Assert (found );
833
805
RETURN_ERROR (ereport (ERROR ,
834
806
(errcode (ERRCODE_JSON_OBJECT_NOT_FOUND ),
835
- errmsg (ERRMSG_JSON_OBJECT_NOT_FOUND ),
836
- errdetail ("jsonpath wildcard member accessor "
837
- "can only be applied to an object" ))));
807
+ errmsg ("jsonpath wildcard member accessor can only be applied to an object" ))));
838
808
}
839
809
break ;
840
810
@@ -964,10 +934,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
964
934
if (!jspIgnoreStructuralErrors (cxt ))
965
935
RETURN_ERROR (ereport (ERROR ,
966
936
(errcode (ERRCODE_JSON_ARRAY_NOT_FOUND ),
967
- errmsg (ERRMSG_JSON_ARRAY_NOT_FOUND ),
968
- errdetail ("jsonpath item method .%s() "
969
- "can only be applied to an array" ,
970
- jspOperationName (jsp -> type )))));
937
+ errmsg ("jsonpath item method .%s() can only be applied to an array" ,
938
+ jspOperationName (jsp -> type )))));
971
939
break ;
972
940
}
973
941
@@ -1020,11 +988,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1020
988
if (have_error )
1021
989
RETURN_ERROR (ereport (ERROR ,
1022
990
(errcode (ERRCODE_NON_NUMERIC_JSON_ITEM ),
1023
- errmsg (ERRMSG_NON_NUMERIC_JSON_ITEM ),
1024
- errdetail ("jsonpath item method .%s() "
1025
- "can only be applied to "
1026
- "a numeric value" ,
1027
- jspOperationName (jsp -> type )))));
991
+ errmsg ("jsonpath item method .%s() can only be applied to a numeric value" ,
992
+ jspOperationName (jsp -> type )))));
1028
993
res = jperOk ;
1029
994
}
1030
995
else if (jb -> type == jbvString )
@@ -1044,10 +1009,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1044
1009
if (have_error || isinf (val ))
1045
1010
RETURN_ERROR (ereport (ERROR ,
1046
1011
(errcode (ERRCODE_NON_NUMERIC_JSON_ITEM ),
1047
- errmsg (ERRMSG_NON_NUMERIC_JSON_ITEM ),
1048
- errdetail ("jsonpath item method .%s() can "
1049
- "only be applied to a numeric value" ,
1050
- jspOperationName (jsp -> type )))));
1012
+ errmsg ("jsonpath item method .%s() can only be applied to a numeric value" ,
1013
+ jspOperationName (jsp -> type )))));
1051
1014
1052
1015
jb = & jbv ;
1053
1016
jb -> type = jbvNumeric ;
@@ -1059,11 +1022,8 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
1059
1022
if (res == jperNotFound )
1060
1023
RETURN_ERROR (ereport (ERROR ,
1061
1024
(errcode (ERRCODE_NON_NUMERIC_JSON_ITEM ),
1062
- errmsg (ERRMSG_NON_NUMERIC_JSON_ITEM ),
1063
- errdetail ("jsonpath item method .%s() "
1064
- "can only be applied to a "
1065
- "string or numeric value" ,
1066
- jspOperationName (jsp -> type )))));
1025
+ errmsg ("jsonpath item method .%s() can only be applied to a string or numeric value" ,
1026
+ jspOperationName (jsp -> type )))));
1067
1027
1068
1028
res = executeNextItem (cxt , jsp , NULL , jb , found , true);
1069
1029
}
@@ -1546,19 +1506,15 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
1546
1506
!(lval = getScalar (JsonValueListHead (& lseq ), jbvNumeric )))
1547
1507
RETURN_ERROR (ereport (ERROR ,
1548
1508
(errcode (ERRCODE_SINGLETON_JSON_ITEM_REQUIRED ),
1549
- errmsg (ERRMSG_SINGLETON_JSON_ITEM_REQUIRED ),
1550
- errdetail ("left operand of binary jsonpath operator %s "
1551
- "is not a singleton numeric value" ,
1552
- jspOperationName (jsp -> type )))));
1509
+ errmsg ("left operand of jsonpath operator %s is not a single numeric value" ,
1510
+ jspOperationName (jsp -> type )))));
1553
1511
1554
1512
if (JsonValueListLength (& rseq ) != 1 ||
1555
1513
!(rval = getScalar (JsonValueListHead (& rseq ), jbvNumeric )))
1556
1514
RETURN_ERROR (ereport (ERROR ,
1557
1515
(errcode (ERRCODE_SINGLETON_JSON_ITEM_REQUIRED ),
1558
- errmsg (ERRMSG_SINGLETON_JSON_ITEM_REQUIRED ),
1559
- errdetail ("right operand of binary jsonpath operator %s "
1560
- "is not a singleton numeric value" ,
1561
- jspOperationName (jsp -> type )))));
1516
+ errmsg ("right operand of jsonpath operator %s is not a single numeric value" ,
1517
+ jspOperationName (jsp -> type )))));
1562
1518
1563
1519
if (jspThrowErrors (cxt ))
1564
1520
{
@@ -1625,10 +1581,8 @@ executeUnaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
1625
1581
1626
1582
RETURN_ERROR (ereport (ERROR ,
1627
1583
(errcode (ERRCODE_JSON_NUMBER_NOT_FOUND ),
1628
- errmsg (ERRMSG_JSON_NUMBER_NOT_FOUND ),
1629
- errdetail ("operand of unary jsonpath operator %s "
1630
- "is not a numeric value" ,
1631
- jspOperationName (jsp -> type )))));
1584
+ errmsg ("operand of unary jsonpath operator %s is not a numeric value" ,
1585
+ jspOperationName (jsp -> type )))));
1632
1586
}
1633
1587
1634
1588
if (func )
@@ -1738,10 +1692,8 @@ executeNumericItemMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
1738
1692
if (!(jb = getScalar (jb , jbvNumeric )))
1739
1693
RETURN_ERROR (ereport (ERROR ,
1740
1694
(errcode (ERRCODE_NON_NUMERIC_JSON_ITEM ),
1741
- errmsg (ERRMSG_NON_NUMERIC_JSON_ITEM ),
1742
- errdetail ("jsonpath item method .%s() can only "
1743
- "be applied to a numeric value" ,
1744
- jspOperationName (jsp -> type )))));
1695
+ errmsg ("jsonpath item method .%s() can only be applied to a numeric value" ,
1696
+ jspOperationName (jsp -> type )))));
1745
1697
1746
1698
datum = DirectFunctionCall1 (func , NumericGetDatum (jb -> val .numeric ));
1747
1699
@@ -1799,10 +1751,8 @@ executeKeyValueMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
1799
1751
if (JsonbType (jb ) != jbvObject || jb -> type != jbvBinary )
1800
1752
RETURN_ERROR (ereport (ERROR ,
1801
1753
(errcode (ERRCODE_JSON_OBJECT_NOT_FOUND ),
1802
- errmsg (ERRMSG_JSON_OBJECT_NOT_FOUND ),
1803
- errdetail ("jsonpath item method .%s() "
1804
- "can only be applied to an object" ,
1805
- jspOperationName (jsp -> type )))));
1754
+ errmsg ("jsonpath item method .%s() can only be applied to an object" ,
1755
+ jspOperationName (jsp -> type )))));
1806
1756
1807
1757
jbc = jb -> val .binary .data ;
1808
1758
@@ -1984,7 +1934,7 @@ getJsonPathVariable(JsonPathExecContext *cxt, JsonPathItem *variable,
1984
1934
{
1985
1935
ereport (ERROR ,
1986
1936
(errcode (ERRCODE_UNDEFINED_OBJECT ),
1987
- errmsg ("cannot find jsonpath variable '%s' " ,
1937
+ errmsg ("cannot find jsonpath variable \"%s\" " ,
1988
1938
pnstrdup (varName , varNameLength ))));
1989
1939
}
1990
1940
@@ -2144,9 +2094,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
2144
2094
!(jbv = getScalar (JsonValueListHead (& found ), jbvNumeric )))
2145
2095
RETURN_ERROR (ereport (ERROR ,
2146
2096
(errcode (ERRCODE_INVALID_JSON_SUBSCRIPT ),
2147
- errmsg (ERRMSG_INVALID_JSON_SUBSCRIPT ),
2148
- errdetail ("jsonpath array subscript is not a "
2149
- "singleton numeric value" ))));
2097
+ errmsg ("jsonpath array subscript is not a single numeric value" ))));
2150
2098
2151
2099
numeric_index = DirectFunctionCall2 (numeric_trunc ,
2152
2100
NumericGetDatum (jbv -> val .numeric ),
@@ -2158,9 +2106,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
2158
2106
if (have_error )
2159
2107
RETURN_ERROR (ereport (ERROR ,
2160
2108
(errcode (ERRCODE_INVALID_JSON_SUBSCRIPT ),
2161
- errmsg (ERRMSG_INVALID_JSON_SUBSCRIPT ),
2162
- errdetail ("jsonpath array subscript is "
2163
- "out of integer range" ))));
2109
+ errmsg ("jsonpath array subscript is out of integer range" ))));
2164
2110
2165
2111
return jperOk ;
2166
2112
}
0 commit comments