Commit 29ceacc3 authored by Alexander Korotkov's avatar Alexander Korotkov

Improve error reporting in jsonpath

This commit contains multiple improvements to error reporting in jsonpath
including but not limited to getting rid of following things:

 * definition of error messages in macros,
 * errdetail() when valueable information could fit to errmsg(),
 * word "singleton" which is not properly explained anywhere,
 * line breaks in error messages.

Reported-by: Tom Lane
Discussion: https://postgr.es/m/14890.1555523005%40sss.pgh.pa.us
Author: Alexander Korotkov
Reviewed-by: Tom Lane
parent b84dbc8e
...@@ -77,16 +77,6 @@ ...@@ -77,16 +77,6 @@
#include "utils/varlena.h" #include "utils/varlena.h"
/* Standard error message for SQL/JSON errors */
#define ERRMSG_JSON_ARRAY_NOT_FOUND "SQL/JSON array not found"
#define ERRMSG_JSON_OBJECT_NOT_FOUND "SQL/JSON object not found"
#define ERRMSG_JSON_MEMBER_NOT_FOUND "SQL/JSON member not found"
#define ERRMSG_JSON_NUMBER_NOT_FOUND "SQL/JSON number not found"
#define ERRMSG_JSON_SCALAR_REQUIRED "SQL/JSON scalar required"
#define ERRMSG_SINGLETON_JSON_ITEM_REQUIRED "singleton SQL/JSON item required"
#define ERRMSG_NON_NUMERIC_JSON_ITEM "non-numeric SQL/JSON item"
#define ERRMSG_INVALID_JSON_SUBSCRIPT "invalid SQL/JSON subscript"
/* /*
* Represents "base object" and it's "id" for .keyvalue() evaluation. * Represents "base object" and it's "id" for .keyvalue() evaluation.
*/ */
...@@ -349,8 +339,7 @@ jsonb_path_match(PG_FUNCTION_ARGS) ...@@ -349,8 +339,7 @@ jsonb_path_match(PG_FUNCTION_ARGS)
if (!silent) if (!silent)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SINGLETON_JSON_ITEM_REQUIRED), (errcode(ERRCODE_SINGLETON_JSON_ITEM_REQUIRED),
errmsg(ERRMSG_SINGLETON_JSON_ITEM_REQUIRED), errmsg("single boolean result is expected")));
errdetail("expression should return a singleton boolean")));
PG_RETURN_NULL(); PG_RETURN_NULL();
} }
...@@ -498,8 +487,8 @@ executeJsonPath(JsonPath *path, Jsonb *vars, Jsonb *json, bool throwErrors, ...@@ -498,8 +487,8 @@ executeJsonPath(JsonPath *path, Jsonb *vars, Jsonb *json, bool throwErrors,
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("jsonb containing jsonpath variables " errmsg("\"vars\" argument is not an object"),
"is not an object"))); errdetail("Jsonpath parameters should be encoded as key-value pairs of \"vars\" object.")));
} }
cxt.vars = vars; cxt.vars = vars;
...@@ -608,24 +597,16 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -608,24 +597,16 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
} }
else if (!jspIgnoreStructuralErrors(cxt)) else if (!jspIgnoreStructuralErrors(cxt))
{ {
StringInfoData keybuf;
char *keystr;
Assert(found); Assert(found);
if (!jspThrowErrors(cxt)) if (!jspThrowErrors(cxt))
return jperError; return jperError;
initStringInfo(&keybuf);
keystr = pnstrdup(key.val.string.val, key.val.string.len);
escape_json(&keybuf, keystr);
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_JSON_MEMBER_NOT_FOUND), \ (errcode(ERRCODE_JSON_MEMBER_NOT_FOUND), \
errmsg(ERRMSG_JSON_MEMBER_NOT_FOUND), errmsg("JSON object does not contain key \"%s\"",
errdetail("JSON object does not contain key %s", pnstrdup(key.val.string.val,
keybuf.data))); key.val.string.len))));
} }
} }
else if (unwrap && JsonbType(jb) == jbvArray) else if (unwrap && JsonbType(jb) == jbvArray)
...@@ -635,9 +616,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -635,9 +616,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
Assert(found); Assert(found);
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_JSON_MEMBER_NOT_FOUND), (errcode(ERRCODE_JSON_MEMBER_NOT_FOUND),
errmsg(ERRMSG_JSON_MEMBER_NOT_FOUND), errmsg("jsonpath member accessor can only be applied to an object"))));
errdetail("jsonpath member accessor can "
"only be applied to an object"))));
} }
break; break;
...@@ -666,9 +645,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -666,9 +645,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
else if (!jspIgnoreStructuralErrors(cxt)) else if (!jspIgnoreStructuralErrors(cxt))
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_JSON_ARRAY_NOT_FOUND), (errcode(ERRCODE_JSON_ARRAY_NOT_FOUND),
errmsg(ERRMSG_JSON_ARRAY_NOT_FOUND), errmsg("jsonpath wildcard array accessor can only be applied to an array"))));
errdetail("jsonpath wildcard array accessor "
"can only be applied to an array"))));
break; break;
case jpiIndexArray: case jpiIndexArray:
...@@ -716,9 +693,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -716,9 +693,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
index_to >= size)) index_to >= size))
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_INVALID_JSON_SUBSCRIPT), (errcode(ERRCODE_INVALID_JSON_SUBSCRIPT),
errmsg(ERRMSG_INVALID_JSON_SUBSCRIPT), errmsg("jsonpath array subscript is out of bounds"))));
errdetail("jsonpath array subscript is "
"out of bounds"))));
if (index_from < 0) if (index_from < 0)
index_from = 0; index_from = 0;
...@@ -775,9 +750,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -775,9 +750,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
{ {
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_JSON_ARRAY_NOT_FOUND), (errcode(ERRCODE_JSON_ARRAY_NOT_FOUND),
errmsg(ERRMSG_JSON_ARRAY_NOT_FOUND), errmsg("jsonpath array accessor can only be applied to an array"))));
errdetail("jsonpath array accessor can "
"only be applied to an array"))));
} }
break; break;
...@@ -789,8 +762,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -789,8 +762,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
bool hasNext = jspGetNext(jsp, &elem); bool hasNext = jspGetNext(jsp, &elem);
if (cxt->innermostArraySize < 0) if (cxt->innermostArraySize < 0)
elog(ERROR, "evaluating jsonpath LAST outside of " elog(ERROR, "evaluating jsonpath LAST outside of array subscript");
"array subscript");
if (!hasNext && !found) if (!hasNext && !found)
{ {
...@@ -832,9 +804,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -832,9 +804,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
Assert(found); Assert(found);
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_JSON_OBJECT_NOT_FOUND), (errcode(ERRCODE_JSON_OBJECT_NOT_FOUND),
errmsg(ERRMSG_JSON_OBJECT_NOT_FOUND), errmsg("jsonpath wildcard member accessor can only be applied to an object"))));
errdetail("jsonpath wildcard member accessor "
"can only be applied to an object"))));
} }
break; break;
...@@ -964,9 +934,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -964,9 +934,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!jspIgnoreStructuralErrors(cxt)) if (!jspIgnoreStructuralErrors(cxt))
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_JSON_ARRAY_NOT_FOUND), (errcode(ERRCODE_JSON_ARRAY_NOT_FOUND),
errmsg(ERRMSG_JSON_ARRAY_NOT_FOUND), errmsg("jsonpath item method .%s() can only be applied to an array",
errdetail("jsonpath item method .%s() "
"can only be applied to an array",
jspOperationName(jsp->type))))); jspOperationName(jsp->type)))));
break; break;
} }
...@@ -1020,10 +988,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -1020,10 +988,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (have_error) if (have_error)
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_JSON_ITEM), (errcode(ERRCODE_NON_NUMERIC_JSON_ITEM),
errmsg(ERRMSG_NON_NUMERIC_JSON_ITEM), errmsg("jsonpath item method .%s() can only be applied to a numeric value",
errdetail("jsonpath item method .%s() "
"can only be applied to "
"a numeric value",
jspOperationName(jsp->type))))); jspOperationName(jsp->type)))));
res = jperOk; res = jperOk;
} }
...@@ -1044,9 +1009,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -1044,9 +1009,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (have_error || isinf(val)) if (have_error || isinf(val))
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_JSON_ITEM), (errcode(ERRCODE_NON_NUMERIC_JSON_ITEM),
errmsg(ERRMSG_NON_NUMERIC_JSON_ITEM), errmsg("jsonpath item method .%s() can only be applied to a numeric value",
errdetail("jsonpath item method .%s() can "
"only be applied to a numeric value",
jspOperationName(jsp->type))))); jspOperationName(jsp->type)))));
jb = &jbv; jb = &jbv;
...@@ -1059,10 +1022,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -1059,10 +1022,7 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (res == jperNotFound) if (res == jperNotFound)
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_JSON_ITEM), (errcode(ERRCODE_NON_NUMERIC_JSON_ITEM),
errmsg(ERRMSG_NON_NUMERIC_JSON_ITEM), errmsg("jsonpath item method .%s() can only be applied to a string or numeric value",
errdetail("jsonpath item method .%s() "
"can only be applied to a "
"string or numeric value",
jspOperationName(jsp->type))))); jspOperationName(jsp->type)))));
res = executeNextItem(cxt, jsp, NULL, jb, found, true); res = executeNextItem(cxt, jsp, NULL, jb, found, true);
...@@ -1546,18 +1506,14 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -1546,18 +1506,14 @@ executeBinaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
!(lval = getScalar(JsonValueListHead(&lseq), jbvNumeric))) !(lval = getScalar(JsonValueListHead(&lseq), jbvNumeric)))
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_SINGLETON_JSON_ITEM_REQUIRED), (errcode(ERRCODE_SINGLETON_JSON_ITEM_REQUIRED),
errmsg(ERRMSG_SINGLETON_JSON_ITEM_REQUIRED), errmsg("left operand of jsonpath operator %s is not a single numeric value",
errdetail("left operand of binary jsonpath operator %s "
"is not a singleton numeric value",
jspOperationName(jsp->type))))); jspOperationName(jsp->type)))));
if (JsonValueListLength(&rseq) != 1 || if (JsonValueListLength(&rseq) != 1 ||
!(rval = getScalar(JsonValueListHead(&rseq), jbvNumeric))) !(rval = getScalar(JsonValueListHead(&rseq), jbvNumeric)))
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_SINGLETON_JSON_ITEM_REQUIRED), (errcode(ERRCODE_SINGLETON_JSON_ITEM_REQUIRED),
errmsg(ERRMSG_SINGLETON_JSON_ITEM_REQUIRED), errmsg("right operand of jsonpath operator %s is not a single numeric value",
errdetail("right operand of binary jsonpath operator %s "
"is not a singleton numeric value",
jspOperationName(jsp->type))))); jspOperationName(jsp->type)))));
if (jspThrowErrors(cxt)) if (jspThrowErrors(cxt))
...@@ -1625,9 +1581,7 @@ executeUnaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -1625,9 +1581,7 @@ executeUnaryArithmExpr(JsonPathExecContext *cxt, JsonPathItem *jsp,
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_JSON_NUMBER_NOT_FOUND), (errcode(ERRCODE_JSON_NUMBER_NOT_FOUND),
errmsg(ERRMSG_JSON_NUMBER_NOT_FOUND), errmsg("operand of unary jsonpath operator %s is not a numeric value",
errdetail("operand of unary jsonpath operator %s "
"is not a numeric value",
jspOperationName(jsp->type))))); jspOperationName(jsp->type)))));
} }
...@@ -1738,9 +1692,7 @@ executeNumericItemMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -1738,9 +1692,7 @@ executeNumericItemMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (!(jb = getScalar(jb, jbvNumeric))) if (!(jb = getScalar(jb, jbvNumeric)))
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_NON_NUMERIC_JSON_ITEM), (errcode(ERRCODE_NON_NUMERIC_JSON_ITEM),
errmsg(ERRMSG_NON_NUMERIC_JSON_ITEM), errmsg("jsonpath item method .%s() can only be applied to a numeric value",
errdetail("jsonpath item method .%s() can only "
"be applied to a numeric value",
jspOperationName(jsp->type))))); jspOperationName(jsp->type)))));
datum = DirectFunctionCall1(func, NumericGetDatum(jb->val.numeric)); datum = DirectFunctionCall1(func, NumericGetDatum(jb->val.numeric));
...@@ -1799,9 +1751,7 @@ executeKeyValueMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, ...@@ -1799,9 +1751,7 @@ executeKeyValueMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
if (JsonbType(jb) != jbvObject || jb->type != jbvBinary) if (JsonbType(jb) != jbvObject || jb->type != jbvBinary)
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_JSON_OBJECT_NOT_FOUND), (errcode(ERRCODE_JSON_OBJECT_NOT_FOUND),
errmsg(ERRMSG_JSON_OBJECT_NOT_FOUND), errmsg("jsonpath item method .%s() can only be applied to an object",
errdetail("jsonpath item method .%s() "
"can only be applied to an object",
jspOperationName(jsp->type))))); jspOperationName(jsp->type)))));
jbc = jb->val.binary.data; jbc = jb->val.binary.data;
...@@ -1984,7 +1934,7 @@ getJsonPathVariable(JsonPathExecContext *cxt, JsonPathItem *variable, ...@@ -1984,7 +1934,7 @@ getJsonPathVariable(JsonPathExecContext *cxt, JsonPathItem *variable,
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT), (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("cannot find jsonpath variable '%s'", errmsg("cannot find jsonpath variable \"%s\"",
pnstrdup(varName, varNameLength)))); pnstrdup(varName, varNameLength))));
} }
...@@ -2144,9 +2094,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb, ...@@ -2144,9 +2094,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
!(jbv = getScalar(JsonValueListHead(&found), jbvNumeric))) !(jbv = getScalar(JsonValueListHead(&found), jbvNumeric)))
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_INVALID_JSON_SUBSCRIPT), (errcode(ERRCODE_INVALID_JSON_SUBSCRIPT),
errmsg(ERRMSG_INVALID_JSON_SUBSCRIPT), errmsg("jsonpath array subscript is not a single numeric value"))));
errdetail("jsonpath array subscript is not a "
"singleton numeric value"))));
numeric_index = DirectFunctionCall2(numeric_trunc, numeric_index = DirectFunctionCall2(numeric_trunc,
NumericGetDatum(jbv->val.numeric), NumericGetDatum(jbv->val.numeric),
...@@ -2158,9 +2106,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb, ...@@ -2158,9 +2106,7 @@ getArrayIndex(JsonPathExecContext *cxt, JsonPathItem *jsp, JsonbValue *jb,
if (have_error) if (have_error)
RETURN_ERROR(ereport(ERROR, RETURN_ERROR(ereport(ERROR,
(errcode(ERRCODE_INVALID_JSON_SUBSCRIPT), (errcode(ERRCODE_INVALID_JSON_SUBSCRIPT),
errmsg(ERRMSG_INVALID_JSON_SUBSCRIPT), errmsg("jsonpath array subscript is out of integer range"))));
errdetail("jsonpath array subscript is "
"out of integer range"))));
return jperOk; return jperOk;
} }
......
...@@ -511,7 +511,11 @@ makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern, ...@@ -511,7 +511,11 @@ makeItemLikeRegex(JsonPathParseItem *expr, JsonPathString *pattern,
cflags |= REG_EXPANDED; cflags |= REG_EXPANDED;
break; break;
default: default:
yyerror(NULL, "unrecognized flag of LIKE_REGEX predicate"); ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("invalid input syntax for type %s", "jsonpath"),
errdetail("unrecognized flag character \"%c\" in LIKE_REGEX predicate",
flags->val[i])));
break; break;
} }
} }
......
...@@ -142,9 +142,9 @@ hex_fail \\x{hex_dig}{0,1} ...@@ -142,9 +142,9 @@ hex_fail \\x{hex_dig}{0,1}
<xnq,xq,xvq,xsq>{hex_char} { parseHexChar(yytext); } <xnq,xq,xvq,xsq>{hex_char} { parseHexChar(yytext); }
<xnq,xq,xvq,xsq>{unicode}*{unicodefail} { yyerror(NULL, "Unicode sequence is invalid"); } <xnq,xq,xvq,xsq>{unicode}*{unicodefail} { yyerror(NULL, "invalid unicode sequence"); }
<xnq,xq,xvq,xsq>{hex_fail} { yyerror(NULL, "Hex character sequence is invalid"); } <xnq,xq,xvq,xsq>{hex_fail} { yyerror(NULL, "invalid hex character sequence"); }
<xnq,xq,xvq,xsq>{unicode}+\\ { <xnq,xq,xvq,xsq>{unicode}+\\ {
/* throw back the \\, and treat as unicode */ /* throw back the \\, and treat as unicode */
...@@ -152,11 +152,11 @@ hex_fail \\x{hex_dig}{0,1} ...@@ -152,11 +152,11 @@ hex_fail \\x{hex_dig}{0,1}
parseUnicode(yytext, yyleng); parseUnicode(yytext, yyleng);
} }
<xnq,xq,xvq,xsq>\\. { yyerror(NULL, "Escape sequence is invalid"); } <xnq,xq,xvq,xsq>\\. { yyerror(NULL, "escape sequence is invalid"); }
<xnq,xq,xvq,xsq>\\ { yyerror(NULL, "Unexpected end after backslash"); } <xnq,xq,xvq,xsq>\\ { yyerror(NULL, "unexpected end after backslash"); }
<xq,xvq,xsq><<EOF>> { yyerror(NULL, "Unexpected end of quoted string"); } <xq,xvq,xsq><<EOF>> { yyerror(NULL, "unexpected end of quoted string"); }
<xq>\" { <xq>\" {
yylval->str = scanstring; yylval->str = scanstring;
...@@ -186,7 +186,7 @@ hex_fail \\x{hex_dig}{0,1} ...@@ -186,7 +186,7 @@ hex_fail \\x{hex_dig}{0,1}
<xc>\* { } <xc>\* { }
<xc><<EOF>> { yyerror(NULL, "Unexpected end of comment"); } <xc><<EOF>> { yyerror(NULL, "unexpected end of comment"); }
\&\& { return AND_P; } \&\& { return AND_P; }
...@@ -261,7 +261,7 @@ hex_fail \\x{hex_dig}{0,1} ...@@ -261,7 +261,7 @@ hex_fail \\x{hex_dig}{0,1}
return INT_P; return INT_P;
} }
({realfail1}|{realfail2}) { yyerror(NULL, "Floating point number is invalid"); } ({realfail1}|{realfail2}) { yyerror(NULL, "invalid floating point number"); }
{any}+ { {any}+ {
addstring(true, yytext, yyleng); addstring(true, yytext, yyleng);
...@@ -295,17 +295,16 @@ jsonpath_yyerror(JsonPathParseResult **result, const char *message) ...@@ -295,17 +295,16 @@ jsonpath_yyerror(JsonPathParseResult **result, const char *message)
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad jsonpath representation"),
/* translator: %s is typically "syntax error" */ /* translator: %s is typically "syntax error" */
errdetail("%s at end of input", message))); errmsg("%s at end of jsonpath input", _(message))));
} }
else else
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
errmsg("bad jsonpath representation"),
/* translator: first %s is typically "syntax error" */ /* translator: first %s is typically "syntax error" */
errdetail("%s at or near \"%s\"", message, yytext))); errmsg("%s at or near \"%s\" of jsonpath input",
_(message), yytext)));
} }
} }
...@@ -495,7 +494,7 @@ hexval(char c) ...@@ -495,7 +494,7 @@ hexval(char c)
return c - 'a' + 0xA; return c - 'a' + 0xA;
if (c >= 'A' && c <= 'F') if (c >= 'A' && c <= 'F')
return c - 'A' + 0xA; return c - 'A' + 0xA;
elog(ERROR, "invalid hexadecimal digit"); jsonpath_yyerror(NULL, "invalid hexadecimal digit");
return 0; /* not reached */ return 0; /* not reached */
} }
......
...@@ -119,8 +119,7 @@ select jsonb '[1]' @? 'strict $[1]'; ...@@ -119,8 +119,7 @@ select jsonb '[1]' @? 'strict $[1]';
(1 row) (1 row)
select jsonb_path_query('[1]', 'strict $[1]'); select jsonb_path_query('[1]', 'strict $[1]');
ERROR: invalid SQL/JSON subscript ERROR: jsonpath array subscript is out of bounds
DETAIL: jsonpath array subscript is out of bounds
select jsonb_path_query('[1]', 'strict $[1]', silent => true); select jsonb_path_query('[1]', 'strict $[1]', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -139,11 +138,9 @@ select jsonb '[1]' @? 'strict $[10000000000000000]'; ...@@ -139,11 +138,9 @@ select jsonb '[1]' @? 'strict $[10000000000000000]';
(1 row) (1 row)
select jsonb_path_query('[1]', 'lax $[10000000000000000]'); select jsonb_path_query('[1]', 'lax $[10000000000000000]');
ERROR: invalid SQL/JSON subscript ERROR: jsonpath array subscript is out of integer range
DETAIL: jsonpath array subscript is out of integer range
select jsonb_path_query('[1]', 'strict $[10000000000000000]'); select jsonb_path_query('[1]', 'strict $[10000000000000000]');
ERROR: invalid SQL/JSON subscript ERROR: jsonpath array subscript is out of integer range
DETAIL: jsonpath array subscript is out of integer range
select jsonb '[1]' @? '$[0]'; select jsonb '[1]' @? '$[0]';
?column? ?column?
---------- ----------
...@@ -241,8 +238,7 @@ select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', silent => true ...@@ -241,8 +238,7 @@ select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'lax $[*].a', silent => true
(1 row) (1 row)
select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', silent => false); select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', silent => false);
ERROR: SQL/JSON member not found ERROR: jsonpath member accessor can only be applied to an object
DETAIL: jsonpath member accessor can only be applied to an object
select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', silent => true); select jsonb_path_exists('[{"a": 1}, {"a": 2}, 3]', 'strict $[*].a', silent => true);
jsonb_path_exists jsonb_path_exists
------------------- -------------------
...@@ -255,11 +251,9 @@ select jsonb_path_query('1', 'lax $.a'); ...@@ -255,11 +251,9 @@ select jsonb_path_query('1', 'lax $.a');
(0 rows) (0 rows)
select jsonb_path_query('1', 'strict $.a'); select jsonb_path_query('1', 'strict $.a');
ERROR: SQL/JSON member not found ERROR: jsonpath member accessor can only be applied to an object
DETAIL: jsonpath member accessor can only be applied to an object
select jsonb_path_query('1', 'strict $.*'); select jsonb_path_query('1', 'strict $.*');
ERROR: SQL/JSON object not found ERROR: jsonpath wildcard member accessor can only be applied to an object
DETAIL: jsonpath wildcard member accessor can only be applied to an object
select jsonb_path_query('1', 'strict $.a', silent => true); select jsonb_path_query('1', 'strict $.a', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -276,8 +270,7 @@ select jsonb_path_query('[]', 'lax $.a'); ...@@ -276,8 +270,7 @@ select jsonb_path_query('[]', 'lax $.a');
(0 rows) (0 rows)
select jsonb_path_query('[]', 'strict $.a'); select jsonb_path_query('[]', 'strict $.a');
ERROR: SQL/JSON member not found ERROR: jsonpath member accessor can only be applied to an object
DETAIL: jsonpath member accessor can only be applied to an object
select jsonb_path_query('[]', 'strict $.a', silent => true); select jsonb_path_query('[]', 'strict $.a', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -289,25 +282,20 @@ select jsonb_path_query('{}', 'lax $.a'); ...@@ -289,25 +282,20 @@ select jsonb_path_query('{}', 'lax $.a');
(0 rows) (0 rows)
select jsonb_path_query('{}', 'strict $.a'); select jsonb_path_query('{}', 'strict $.a');
ERROR: SQL/JSON member not found ERROR: JSON object does not contain key "a"
DETAIL: JSON object does not contain key "a"
select jsonb_path_query('{}', 'strict $.a', silent => true); select jsonb_path_query('{}', 'strict $.a', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
(0 rows) (0 rows)
select jsonb_path_query('1', 'strict $[1]'); select jsonb_path_query('1', 'strict $[1]');
ERROR: SQL/JSON array not found ERROR: jsonpath array accessor can only be applied to an array
DETAIL: jsonpath array accessor can only be applied to an array
select jsonb_path_query('1', 'strict $[*]'); select jsonb_path_query('1', 'strict $[*]');
ERROR: SQL/JSON array not found ERROR: jsonpath wildcard array accessor can only be applied to an array
DETAIL: jsonpath wildcard array accessor can only be applied to an array
select jsonb_path_query('[]', 'strict $[1]'); select jsonb_path_query('[]', 'strict $[1]');
ERROR: invalid SQL/JSON subscript ERROR: jsonpath array subscript is out of bounds
DETAIL: jsonpath array subscript is out of bounds
select jsonb_path_query('[]', 'strict $["a"]'); select jsonb_path_query('[]', 'strict $["a"]');
ERROR: invalid SQL/JSON subscript ERROR: jsonpath array subscript is not a single numeric value
DETAIL: jsonpath array subscript is not a singleton numeric value
select jsonb_path_query('1', 'strict $[1]', silent => true); select jsonb_path_query('1', 'strict $[1]', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -437,8 +425,7 @@ select jsonb_path_query('[1,2,3]', 'lax $[*]'); ...@@ -437,8 +425,7 @@ select jsonb_path_query('[1,2,3]', 'lax $[*]');
(3 rows) (3 rows)
select jsonb_path_query('[1,2,3]', 'strict $[*].a'); select jsonb_path_query('[1,2,3]', 'strict $[*].a');
ERROR: SQL/JSON member not found ERROR: jsonpath member accessor can only be applied to an object
DETAIL: jsonpath member accessor can only be applied to an object
select jsonb_path_query('[1,2,3]', 'strict $[*].a', silent => true); select jsonb_path_query('[1,2,3]', 'strict $[*].a', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -455,8 +442,7 @@ select jsonb_path_query('[]', '$[last ? (exists(last))]'); ...@@ -455,8 +442,7 @@ select jsonb_path_query('[]', '$[last ? (exists(last))]');
(0 rows) (0 rows)
select jsonb_path_query('[]', 'strict $[last]'); select jsonb_path_query('[]', 'strict $[last]');
ERROR: invalid SQL/JSON subscript ERROR: jsonpath array subscript is out of bounds
DETAIL: jsonpath array subscript is out of bounds
select jsonb_path_query('[]', 'strict $[last]', silent => true); select jsonb_path_query('[]', 'strict $[last]', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -487,8 +473,7 @@ select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "number")]'); ...@@ -487,8 +473,7 @@ select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "number")]');
(1 row) (1 row)
select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "string")]'); select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "string")]');
ERROR: invalid SQL/JSON subscript ERROR: jsonpath array subscript is not a single numeric value
DETAIL: jsonpath array subscript is not a singleton numeric value
select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "string")]', silent => true); select jsonb_path_query('[1,2,3]', '$[last ? (@.type() == "string")]', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -501,11 +486,13 @@ select * from jsonb_path_query('{"a": 10}', '$'); ...@@ -501,11 +486,13 @@ select * from jsonb_path_query('{"a": 10}', '$');
(1 row) (1 row)
select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)'); select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)');
ERROR: cannot find jsonpath variable 'value' ERROR: cannot find jsonpath variable "value"
select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '1'); select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '1');
ERROR: jsonb containing jsonpath variables is not an object ERROR: "vars" argument is not an object
DETAIL: Jsonpath parameters should be encoded as key-value pairs of "vars" object.
select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '[{"value" : 13}]'); select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '[{"value" : 13}]');
ERROR: jsonb containing jsonpath variables is not an object ERROR: "vars" argument is not an object
DETAIL: Jsonpath parameters should be encoded as key-value pairs of "vars" object.
select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '{"value" : 13}'); select * from jsonb_path_query('{"a": 10}', '$ ? (@.a < $value)', '{"value" : 13}');
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1067,17 +1054,13 @@ ERROR: division by zero ...@@ -1067,17 +1054,13 @@ ERROR: division by zero
select jsonb_path_query('0', '-(3 + 1 % $)'); select jsonb_path_query('0', '-(3 + 1 % $)');
ERROR: division by zero ERROR: division by zero
select jsonb_path_query('1', '$ + "2"'); select jsonb_path_query('1', '$ + "2"');
ERROR: singleton SQL/JSON item required ERROR: right operand of jsonpath operator + is not a single numeric value
DETAIL: right operand of binary jsonpath operator + is not a singleton numeric value
select jsonb_path_query('[1, 2]', '3 * $'); select jsonb_path_query('[1, 2]', '3 * $');
ERROR: singleton SQL/JSON item required ERROR: right operand of jsonpath operator * is not a single numeric value
DETAIL: right operand of binary jsonpath operator * is not a singleton numeric value
select jsonb_path_query('"a"', '-$'); select jsonb_path_query('"a"', '-$');
ERROR: SQL/JSON number not found ERROR: operand of unary jsonpath operator - is not a numeric value
DETAIL: operand of unary jsonpath operator - is not a numeric value
select jsonb_path_query('[1,"2",3]', '+$'); select jsonb_path_query('[1,"2",3]', '+$');
ERROR: SQL/JSON number not found ERROR: operand of unary jsonpath operator + is not a numeric value
DETAIL: operand of unary jsonpath operator + is not a numeric value
select jsonb_path_query('1', '$ + "2"', silent => true); select jsonb_path_query('1', '$ + "2"', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1146,8 +1129,7 @@ select jsonb_path_query('{"a": [2, 3, 4]}', 'lax -$.a'); ...@@ -1146,8 +1129,7 @@ select jsonb_path_query('{"a": [2, 3, 4]}', 'lax -$.a');
-- should fail -- should fail
select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3'); select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3');
ERROR: singleton SQL/JSON item required ERROR: left operand of jsonpath operator * is not a single numeric value
DETAIL: left operand of binary jsonpath operator * is not a singleton numeric value
select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3', silent => true); select jsonb_path_query('{"a": [1, 2]}', 'lax $.a * 3', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1346,8 +1328,7 @@ select jsonb_path_query('[1, 2, 3]', 'strict ($[*].a > 3).type()'); ...@@ -1346,8 +1328,7 @@ select jsonb_path_query('[1, 2, 3]', 'strict ($[*].a > 3).type()');
(1 row) (1 row)
select jsonb_path_query('[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'strict $[*].size()'); select jsonb_path_query('[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'strict $[*].size()');
ERROR: SQL/JSON array not found ERROR: jsonpath item method .size() can only be applied to an array
DETAIL: jsonpath item method .size() can only be applied to an array
select jsonb_path_query('[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'strict $[*].size()', silent => true); select jsonb_path_query('[1,null,true,"11",[],[1],[1,2,3],{},{"a":1,"b":2}]', 'strict $[*].size()', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1418,8 +1399,7 @@ select jsonb_path_query('[0, 1, -2, -3.4, 5.6]', '$[*].ceiling().abs().type()'); ...@@ -1418,8 +1399,7 @@ select jsonb_path_query('[0, 1, -2, -3.4, 5.6]', '$[*].ceiling().abs().type()');
(5 rows) (5 rows)
select jsonb_path_query('[{},1]', '$[*].keyvalue()'); select jsonb_path_query('[{},1]', '$[*].keyvalue()');
ERROR: SQL/JSON object not found ERROR: jsonpath item method .keyvalue() can only be applied to an object
DETAIL: jsonpath item method .keyvalue() can only be applied to an object
select jsonb_path_query('[{},1]', '$[*].keyvalue()', silent => true); select jsonb_path_query('[{},1]', '$[*].keyvalue()', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1447,8 +1427,7 @@ select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', '$[*].ke ...@@ -1447,8 +1427,7 @@ select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', '$[*].ke
(3 rows) (3 rows)
select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'strict $.keyvalue()'); select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'strict $.keyvalue()');
ERROR: SQL/JSON object not found ERROR: jsonpath item method .keyvalue() can only be applied to an object
DETAIL: jsonpath item method .keyvalue() can only be applied to an object
select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'lax $.keyvalue()'); select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'lax $.keyvalue()');
jsonb_path_query jsonb_path_query
----------------------------------------------- -----------------------------------------------
...@@ -1458,8 +1437,7 @@ select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'lax $.k ...@@ -1458,8 +1437,7 @@ select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'lax $.k
(3 rows) (3 rows)
select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'strict $.keyvalue().a'); select jsonb_path_query('[{"a": 1, "b": [1, 2]}, {"c": {"a": "bbb"}}]', 'strict $.keyvalue().a');
ERROR: SQL/JSON object not found ERROR: jsonpath item method .keyvalue() can only be applied to an object
DETAIL: jsonpath item method .keyvalue() can only be applied to an object
select jsonb '{"a": 1, "b": [1, 2]}' @? 'lax $.keyvalue()'; select jsonb '{"a": 1, "b": [1, 2]}' @? 'lax $.keyvalue()';
?column? ?column?
---------- ----------
...@@ -1473,11 +1451,9 @@ select jsonb '{"a": 1, "b": [1, 2]}' @? 'lax $.keyvalue().key'; ...@@ -1473,11 +1451,9 @@ select jsonb '{"a": 1, "b": [1, 2]}' @? 'lax $.keyvalue().key';
(1 row) (1 row)
select jsonb_path_query('null', '$.double()'); select jsonb_path_query('null', '$.double()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .double() can only be applied to a string or numeric value
DETAIL: jsonpath item method .double() can only be applied to a string or numeric value
select jsonb_path_query('true', '$.double()'); select jsonb_path_query('true', '$.double()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .double() can only be applied to a string or numeric value
DETAIL: jsonpath item method .double() can only be applied to a string or numeric value
select jsonb_path_query('null', '$.double()', silent => true); select jsonb_path_query('null', '$.double()', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1494,11 +1470,9 @@ select jsonb_path_query('[]', '$.double()'); ...@@ -1494,11 +1470,9 @@ select jsonb_path_query('[]', '$.double()');
(0 rows) (0 rows)
select jsonb_path_query('[]', 'strict $.double()'); select jsonb_path_query('[]', 'strict $.double()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .double() can only be applied to a string or numeric value
DETAIL: jsonpath item method .double() can only be applied to a string or numeric value
select jsonb_path_query('{}', '$.double()'); select jsonb_path_query('{}', '$.double()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .double() can only be applied to a string or numeric value
DETAIL: jsonpath item method .double() can only be applied to a string or numeric value
select jsonb_path_query('[]', 'strict $.double()', silent => true); select jsonb_path_query('[]', 'strict $.double()', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1522,8 +1496,7 @@ select jsonb_path_query('"1.23"', '$.double()'); ...@@ -1522,8 +1496,7 @@ select jsonb_path_query('"1.23"', '$.double()');
(1 row) (1 row)
select jsonb_path_query('"1.23aaa"', '$.double()'); select jsonb_path_query('"1.23aaa"', '$.double()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .double() can only be applied to a numeric value
DETAIL: jsonpath item method .double() can only be applied to a numeric value
select jsonb_path_query('"nan"', '$.double()'); select jsonb_path_query('"nan"', '$.double()');
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1537,11 +1510,9 @@ select jsonb_path_query('"NaN"', '$.double()'); ...@@ -1537,11 +1510,9 @@ select jsonb_path_query('"NaN"', '$.double()');
(1 row) (1 row)
select jsonb_path_query('"inf"', '$.double()'); select jsonb_path_query('"inf"', '$.double()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .double() can only be applied to a numeric value
DETAIL: jsonpath item method .double() can only be applied to a numeric value
select jsonb_path_query('"-inf"', '$.double()'); select jsonb_path_query('"-inf"', '$.double()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .double() can only be applied to a numeric value
DETAIL: jsonpath item method .double() can only be applied to a numeric value
select jsonb_path_query('"inf"', '$.double()', silent => true); select jsonb_path_query('"inf"', '$.double()', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1553,14 +1524,11 @@ select jsonb_path_query('"-inf"', '$.double()', silent => true); ...@@ -1553,14 +1524,11 @@ select jsonb_path_query('"-inf"', '$.double()', silent => true);
(0 rows) (0 rows)
select jsonb_path_query('{}', '$.abs()'); select jsonb_path_query('{}', '$.abs()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .abs() can only be applied to a numeric value
DETAIL: jsonpath item method .abs() can only be applied to a numeric value
select jsonb_path_query('true', '$.floor()'); select jsonb_path_query('true', '$.floor()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .floor() can only be applied to a numeric value
DETAIL: jsonpath item method .floor() can only be applied to a numeric value
select jsonb_path_query('"1.2"', '$.ceiling()'); select jsonb_path_query('"1.2"', '$.ceiling()');
ERROR: non-numeric SQL/JSON item ERROR: jsonpath item method .ceiling() can only be applied to a numeric value
DETAIL: jsonpath item method .ceiling() can only be applied to a numeric value
select jsonb_path_query('{}', '$.abs()', silent => true); select jsonb_path_query('{}', '$.abs()', silent => true);
jsonb_path_query jsonb_path_query
------------------ ------------------
...@@ -1668,8 +1636,7 @@ SELECT jsonb_path_query('[{"a": 1}, {"a": 2}]', '$[*] ? (@.a > 10)'); ...@@ -1668,8 +1636,7 @@ SELECT jsonb_path_query('[{"a": 1}, {"a": 2}]', '$[*] ? (@.a > 10)');
(0 rows) (0 rows)
SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a'); SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a');
ERROR: SQL/JSON member not found ERROR: JSON object does not contain key "a"
DETAIL: JSON object does not contain key "a"
SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}]', '$[*].a'); SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}]', '$[*].a');
jsonb_path_query_array jsonb_path_query_array
------------------------ ------------------------
...@@ -1701,8 +1668,7 @@ SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*]. ...@@ -1701,8 +1668,7 @@ SELECT jsonb_path_query_array('[{"a": 1}, {"a": 2}, {"a": 3}, {"a": 5}]', '$[*].
(1 row) (1 row)
SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a'); SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a');
ERROR: SQL/JSON member not found ERROR: JSON object does not contain key "a"
DETAIL: JSON object does not contain key "a"
SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a', silent => true); SELECT jsonb_path_query_first('[{"a": 1}, {"a": 2}, {}]', 'strict $[*].a', silent => true);
jsonb_path_query_first jsonb_path_query_first
------------------------ ------------------------
...@@ -1794,23 +1760,17 @@ SELECT jsonb_path_match('1', '$', silent => true); ...@@ -1794,23 +1760,17 @@ SELECT jsonb_path_match('1', '$', silent => true);
(1 row) (1 row)
SELECT jsonb_path_match('1', '$', silent => false); SELECT jsonb_path_match('1', '$', silent => false);
ERROR: singleton SQL/JSON item required ERROR: single boolean result is expected
DETAIL: expression should return a singleton boolean
SELECT jsonb_path_match('"a"', '$', silent => false); SELECT jsonb_path_match('"a"', '$', silent => false);
ERROR: singleton SQL/JSON item required ERROR: single boolean result is expected
DETAIL: expression should return a singleton boolean
SELECT jsonb_path_match('{}', '$', silent => false); SELECT jsonb_path_match('{}', '$', silent => false);
ERROR: singleton SQL/JSON item required ERROR: single boolean result is expected
DETAIL: expression should return a singleton boolean
SELECT jsonb_path_match('[true]', '$', silent => false); SELECT jsonb_path_match('[true]', '$', silent => false);
ERROR: singleton SQL/JSON item required ERROR: single boolean result is expected
DETAIL: expression should return a singleton boolean
SELECT jsonb_path_match('{}', 'lax $.a', silent => false); SELECT jsonb_path_match('{}', 'lax $.a', silent => false);
ERROR: singleton SQL/JSON item required ERROR: single boolean result is expected
DETAIL: expression should return a singleton boolean
SELECT jsonb_path_match('{}', 'strict $.a', silent => false); SELECT jsonb_path_match('{}', 'strict $.a', silent => false);
ERROR: SQL/JSON member not found ERROR: JSON object does not contain key "a"
DETAIL: JSON object does not contain key "a"
SELECT jsonb_path_match('{}', 'strict $.a', silent => true); SELECT jsonb_path_match('{}', 'strict $.a', silent => true);
jsonb_path_match jsonb_path_match
------------------ ------------------
...@@ -1818,8 +1778,7 @@ SELECT jsonb_path_match('{}', 'strict $.a', silent => true); ...@@ -1818,8 +1778,7 @@ SELECT jsonb_path_match('{}', 'strict $.a', silent => true);
(1 row) (1 row)
SELECT jsonb_path_match('[true, true]', '$[*]', silent => false); SELECT jsonb_path_match('[true, true]', '$[*]', silent => false);
ERROR: singleton SQL/JSON item required ERROR: single boolean result is expected
DETAIL: expression should return a singleton boolean
SELECT jsonb '[{"a": 1}, {"a": 2}]' @@ '$[*].a > 1'; SELECT jsonb '[{"a": 1}, {"a": 2}]' @@ '$[*].a > 1';
?column? ?column?
---------- ----------
......
...@@ -454,10 +454,10 @@ select '$ ? (@ like_regex "pattern" flag "xsms")'::jsonpath; ...@@ -454,10 +454,10 @@ select '$ ? (@ like_regex "pattern" flag "xsms")'::jsonpath;
(1 row) (1 row)
select '$ ? (@ like_regex "pattern" flag "a")'::jsonpath; select '$ ? (@ like_regex "pattern" flag "a")'::jsonpath;
ERROR: bad jsonpath representation ERROR: invalid input syntax for type jsonpath
LINE 1: select '$ ? (@ like_regex "pattern" flag "a")'::jsonpath; LINE 1: select '$ ? (@ like_regex "pattern" flag "a")'::jsonpath;
^ ^
DETAIL: unrecognized flag of LIKE_REGEX predicate at or near """ DETAIL: unrecognized flag character "a" in LIKE_REGEX predicate
select '$ < 1'::jsonpath; select '$ < 1'::jsonpath;
jsonpath jsonpath
---------- ----------
...@@ -547,20 +547,17 @@ select '$ ? (@.a < +1)'::jsonpath; ...@@ -547,20 +547,17 @@ select '$ ? (@.a < +1)'::jsonpath;
(1 row) (1 row)
select '$ ? (@.a < .1)'::jsonpath; select '$ ? (@.a < .1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < .1)'::jsonpath; LINE 1: select '$ ? (@.a < .1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < -.1)'::jsonpath; select '$ ? (@.a < -.1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < -.1)'::jsonpath; LINE 1: select '$ ? (@.a < -.1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < +.1)'::jsonpath; select '$ ? (@.a < +.1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < +.1)'::jsonpath; LINE 1: select '$ ? (@.a < +.1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < 0.1)'::jsonpath; select '$ ? (@.a < 0.1)'::jsonpath;
jsonpath jsonpath
----------------- -----------------
...@@ -616,20 +613,17 @@ select '$ ? (@.a < +1e1)'::jsonpath; ...@@ -616,20 +613,17 @@ select '$ ? (@.a < +1e1)'::jsonpath;
(1 row) (1 row)
select '$ ? (@.a < .1e1)'::jsonpath; select '$ ? (@.a < .1e1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < .1e1)'::jsonpath; LINE 1: select '$ ? (@.a < .1e1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < -.1e1)'::jsonpath; select '$ ? (@.a < -.1e1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < -.1e1)'::jsonpath; LINE 1: select '$ ? (@.a < -.1e1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < +.1e1)'::jsonpath; select '$ ? (@.a < +.1e1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < +.1e1)'::jsonpath; LINE 1: select '$ ? (@.a < +.1e1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < 0.1e1)'::jsonpath; select '$ ? (@.a < 0.1e1)'::jsonpath;
jsonpath jsonpath
--------------- ---------------
...@@ -685,20 +679,17 @@ select '$ ? (@.a < +1e-1)'::jsonpath; ...@@ -685,20 +679,17 @@ select '$ ? (@.a < +1e-1)'::jsonpath;
(1 row) (1 row)
select '$ ? (@.a < .1e-1)'::jsonpath; select '$ ? (@.a < .1e-1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < .1e-1)'::jsonpath; LINE 1: select '$ ? (@.a < .1e-1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < -.1e-1)'::jsonpath; select '$ ? (@.a < -.1e-1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < -.1e-1)'::jsonpath; LINE 1: select '$ ? (@.a < -.1e-1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < +.1e-1)'::jsonpath; select '$ ? (@.a < +.1e-1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < +.1e-1)'::jsonpath; LINE 1: select '$ ? (@.a < +.1e-1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < 0.1e-1)'::jsonpath; select '$ ? (@.a < 0.1e-1)'::jsonpath;
jsonpath jsonpath
------------------ ------------------
...@@ -754,20 +745,17 @@ select '$ ? (@.a < +1e+1)'::jsonpath; ...@@ -754,20 +745,17 @@ select '$ ? (@.a < +1e+1)'::jsonpath;
(1 row) (1 row)
select '$ ? (@.a < .1e+1)'::jsonpath; select '$ ? (@.a < .1e+1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < .1e+1)'::jsonpath; LINE 1: select '$ ? (@.a < .1e+1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < -.1e+1)'::jsonpath; select '$ ? (@.a < -.1e+1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < -.1e+1)'::jsonpath; LINE 1: select '$ ? (@.a < -.1e+1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < +.1e+1)'::jsonpath; select '$ ? (@.a < +.1e+1)'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '$ ? (@.a < +.1e+1)'::jsonpath; LINE 1: select '$ ? (@.a < +.1e+1)'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '$ ? (@.a < 0.1e+1)'::jsonpath; select '$ ? (@.a < 0.1e+1)'::jsonpath;
jsonpath jsonpath
--------------- ---------------
...@@ -811,10 +799,9 @@ select '0'::jsonpath; ...@@ -811,10 +799,9 @@ select '0'::jsonpath;
(1 row) (1 row)
select '00'::jsonpath; select '00'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected IDENT_P at end of jsonpath input
LINE 1: select '00'::jsonpath; LINE 1: select '00'::jsonpath;
^ ^
DETAIL: syntax error, unexpected IDENT_P at end of input
select '0.0'::jsonpath; select '0.0'::jsonpath;
jsonpath jsonpath
---------- ----------
...@@ -870,10 +857,9 @@ select '0.0010e+2'::jsonpath; ...@@ -870,10 +857,9 @@ select '0.0010e+2'::jsonpath;
(1 row) (1 row)
select '1e'::jsonpath; select '1e'::jsonpath;
ERROR: bad jsonpath representation ERROR: invalid floating point number at or near "1e" of jsonpath input
LINE 1: select '1e'::jsonpath; LINE 1: select '1e'::jsonpath;
^ ^
DETAIL: Floating point number is invalid at or near "1e"
select '1.e'::jsonpath; select '1.e'::jsonpath;
jsonpath jsonpath
---------- ----------
...@@ -881,10 +867,9 @@ select '1.e'::jsonpath; ...@@ -881,10 +867,9 @@ select '1.e'::jsonpath;
(1 row) (1 row)
select '1.2e'::jsonpath; select '1.2e'::jsonpath;
ERROR: bad jsonpath representation ERROR: invalid floating point number at or near "1.2e" of jsonpath input
LINE 1: select '1.2e'::jsonpath; LINE 1: select '1.2e'::jsonpath;
^ ^
DETAIL: Floating point number is invalid at or near "1.2e"
select '1.2.e'::jsonpath; select '1.2.e'::jsonpath;
jsonpath jsonpath
---------- ----------
...@@ -940,22 +925,18 @@ select '(1.2).e3'::jsonpath; ...@@ -940,22 +925,18 @@ select '(1.2).e3'::jsonpath;
(1 row) (1 row)
select '1..e'::jsonpath; select '1..e'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '1..e'::jsonpath; LINE 1: select '1..e'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '1..e3'::jsonpath; select '1..e3'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected '.' at or near "." of jsonpath input
LINE 1: select '1..e3'::jsonpath; LINE 1: select '1..e3'::jsonpath;
^ ^
DETAIL: syntax error, unexpected '.' at or near "."
select '(1.).e'::jsonpath; select '(1.).e'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected ')' at or near ")" of jsonpath input
LINE 1: select '(1.).e'::jsonpath; LINE 1: select '(1.).e'::jsonpath;
^ ^
DETAIL: syntax error, unexpected ')' at or near ")"
select '(1.).e3'::jsonpath; select '(1.).e3'::jsonpath;
ERROR: bad jsonpath representation ERROR: syntax error, unexpected ')' at or near ")" of jsonpath input
LINE 1: select '(1.).e3'::jsonpath; LINE 1: select '(1.).e3'::jsonpath;
^ ^
DETAIL: syntax error, unexpected ')' at or near ")"
...@@ -2,20 +2,17 @@ ...@@ -2,20 +2,17 @@
-- checks for double-quoted values -- checks for double-quoted values
-- basic unicode input -- basic unicode input
SELECT '"\u"'::jsonpath; -- ERROR, incomplete escape SELECT '"\u"'::jsonpath; -- ERROR, incomplete escape
ERROR: bad jsonpath representation ERROR: invalid unicode sequence at or near "\u" of jsonpath input
LINE 1: SELECT '"\u"'::jsonpath; LINE 1: SELECT '"\u"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u"
SELECT '"\u00"'::jsonpath; -- ERROR, incomplete escape SELECT '"\u00"'::jsonpath; -- ERROR, incomplete escape
ERROR: bad jsonpath representation ERROR: invalid unicode sequence at or near "\u00" of jsonpath input
LINE 1: SELECT '"\u00"'::jsonpath; LINE 1: SELECT '"\u00"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u00"
SELECT '"\u000g"'::jsonpath; -- ERROR, g is not a hex digit SELECT '"\u000g"'::jsonpath; -- ERROR, g is not a hex digit
ERROR: bad jsonpath representation ERROR: invalid unicode sequence at or near "\u000" of jsonpath input
LINE 1: SELECT '"\u000g"'::jsonpath; LINE 1: SELECT '"\u000g"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u000"
SELECT '"\u0000"'::jsonpath; -- OK, legal escape SELECT '"\u0000"'::jsonpath; -- OK, legal escape
ERROR: unsupported Unicode escape sequence ERROR: unsupported Unicode escape sequence
LINE 1: SELECT '"\u0000"'::jsonpath; LINE 1: SELECT '"\u0000"'::jsonpath;
...@@ -165,20 +162,17 @@ DETAIL: \u0000 cannot be converted to text. ...@@ -165,20 +162,17 @@ DETAIL: \u0000 cannot be converted to text.
-- checks for quoted key names -- checks for quoted key names
-- basic unicode input -- basic unicode input
SELECT '$."\u"'::jsonpath; -- ERROR, incomplete escape SELECT '$."\u"'::jsonpath; -- ERROR, incomplete escape
ERROR: bad jsonpath representation ERROR: invalid unicode sequence at or near "\u" of jsonpath input
LINE 1: SELECT '$."\u"'::jsonpath; LINE 1: SELECT '$."\u"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u"
SELECT '$."\u00"'::jsonpath; -- ERROR, incomplete escape SELECT '$."\u00"'::jsonpath; -- ERROR, incomplete escape
ERROR: bad jsonpath representation ERROR: invalid unicode sequence at or near "\u00" of jsonpath input
LINE 1: SELECT '$."\u00"'::jsonpath; LINE 1: SELECT '$."\u00"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u00"
SELECT '$."\u000g"'::jsonpath; -- ERROR, g is not a hex digit SELECT '$."\u000g"'::jsonpath; -- ERROR, g is not a hex digit
ERROR: bad jsonpath representation ERROR: invalid unicode sequence at or near "\u000" of jsonpath input
LINE 1: SELECT '$."\u000g"'::jsonpath; LINE 1: SELECT '$."\u000g"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u000"
SELECT '$."\u0000"'::jsonpath; -- OK, legal escape SELECT '$."\u0000"'::jsonpath; -- OK, legal escape
ERROR: unsupported Unicode escape sequence ERROR: unsupported Unicode escape sequence
LINE 1: SELECT '$."\u0000"'::jsonpath; LINE 1: SELECT '$."\u0000"'::jsonpath;
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
-- checks for double-quoted values -- checks for double-quoted values
-- basic unicode input -- basic unicode input
SELECT '"\u"'::jsonpath; -- ERROR, incomplete escape SELECT '"\u"'::jsonpath; -- ERROR, incomplete escape
ERROR: bad jsonpath representation ERROR: invalid input syntax for type jsonpath
LINE 1: SELECT '"\u"'::jsonpath; LINE 1: SELECT '"\u"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u" DETAIL: Unicode sequence is invalid at or near "\u"
SELECT '"\u00"'::jsonpath; -- ERROR, incomplete escape SELECT '"\u00"'::jsonpath; -- ERROR, incomplete escape
ERROR: bad jsonpath representation ERROR: invalid input syntax for type jsonpath
LINE 1: SELECT '"\u00"'::jsonpath; LINE 1: SELECT '"\u00"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u00" DETAIL: Unicode sequence is invalid at or near "\u00"
SELECT '"\u000g"'::jsonpath; -- ERROR, g is not a hex digit SELECT '"\u000g"'::jsonpath; -- ERROR, g is not a hex digit
ERROR: bad jsonpath representation ERROR: invalid input syntax for type jsonpath
LINE 1: SELECT '"\u000g"'::jsonpath; LINE 1: SELECT '"\u000g"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u000" DETAIL: Unicode sequence is invalid at or near "\u000"
...@@ -156,17 +156,17 @@ DETAIL: \u0000 cannot be converted to text. ...@@ -156,17 +156,17 @@ DETAIL: \u0000 cannot be converted to text.
-- checks for quoted key names -- checks for quoted key names
-- basic unicode input -- basic unicode input
SELECT '$."\u"'::jsonpath; -- ERROR, incomplete escape SELECT '$."\u"'::jsonpath; -- ERROR, incomplete escape
ERROR: bad jsonpath representation ERROR: invalid input syntax for type jsonpath
LINE 1: SELECT '$."\u"'::jsonpath; LINE 1: SELECT '$."\u"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u" DETAIL: Unicode sequence is invalid at or near "\u"
SELECT '$."\u00"'::jsonpath; -- ERROR, incomplete escape SELECT '$."\u00"'::jsonpath; -- ERROR, incomplete escape
ERROR: bad jsonpath representation ERROR: invalid input syntax for type jsonpath
LINE 1: SELECT '$."\u00"'::jsonpath; LINE 1: SELECT '$."\u00"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u00" DETAIL: Unicode sequence is invalid at or near "\u00"
SELECT '$."\u000g"'::jsonpath; -- ERROR, g is not a hex digit SELECT '$."\u000g"'::jsonpath; -- ERROR, g is not a hex digit
ERROR: bad jsonpath representation ERROR: invalid input syntax for type jsonpath
LINE 1: SELECT '$."\u000g"'::jsonpath; LINE 1: SELECT '$."\u000g"'::jsonpath;
^ ^
DETAIL: Unicode sequence is invalid at or near "\u000" DETAIL: Unicode sequence is invalid at or near "\u000"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment