On 2022-06-26 Su 11:44, Erik Rijkers wrote: > JSON/SQL jsonpath > > For example, a jsonpath string with deliberate typo 'like_regexp' > (instead of 'like_regex'): > > select js > from (values (jsonb '{}')) as f(js) > where js @? '$ ? (@ like_regexp "^xxx")'; > > ERROR: syntax error, unexpected IDENT_P at or near " " of jsonpath input > LINE 1: ...s from (values (jsonb '{}')) as f(js) where js @? '$ ? (@ > li... > ^ > > Both 'IDENT_P' and 'at or near " "' seem pretty useless. > > Perhaps some improvement can be thought of? > > Similar messages in release 14 seem to use 'invalid token', which is > better: > > select js > from (values (jsonb '{"a":"b"}')) as f(js) > where js @? '$ ? (@.a .= "b")'; > ERROR: syntax error, unexpected invalid token at or near "=" of > jsonpath input > >
Yeah :-( This apparently goes back to the original jsonpath commit 72b6460336e. There are similar error messages in the back branch regression tests: andrew@ub20:pgl $ grep -r IDENT_P pg_*/src/test/regress/expected/ pg_12/src/test/regress/expected/jsonpath.out:ERROR: syntax error, unexpected IDENT_P at end of jsonpath input pg_13/src/test/regress/expected/jsonpath.out:ERROR: syntax error, unexpected IDENT_P at end of jsonpath input pg_14/src/test/regress/expected/jsonpath.out:ERROR: syntax error, unexpected IDENT_P at end of jsonpath input For some reason the parser contains a '%error-verbose' directive, unlike all our other bison parsers. Removing that fixes it, as in this patch. I'm a bit inclined to say we should backpatch the removal of the directive, but I guess a lack of complaints suggests it's not a huge issue. cheers andrew -- Andrew Dunstan EDB: https://www.enterprisedb.com
diff --git a/src/backend/utils/adt/jsonpath_gram.y b/src/backend/utils/adt/jsonpath_gram.y index 06d4c8c229..57f6beb27b 100644 --- a/src/backend/utils/adt/jsonpath_gram.y +++ b/src/backend/utils/adt/jsonpath_gram.y @@ -74,7 +74,6 @@ static JsonPathParseItem *makeItemLikeRegex(JsonPathParseItem *expr, %pure-parser %expect 0 %name-prefix="jsonpath_yy" -%error-verbose %parse-param {JsonPathParseResult **result} %union diff --git a/src/test/regress/expected/jsonb_sqljson.out b/src/test/regress/expected/jsonb_sqljson.out index ec7dc50593..e2f7df50a8 100644 --- a/src/test/regress/expected/jsonb_sqljson.out +++ b/src/test/regress/expected/jsonb_sqljson.out @@ -2083,7 +2083,7 @@ SELECT JSON_QUERY(jsonb '{"a": 123}', '$' || '.' || 'a' WITH WRAPPER); -- Should fail (invalid path) SELECT JSON_QUERY(jsonb '{"a": 123}', 'error' || ' ' || 'error'); -ERROR: syntax error, unexpected IDENT_P at or near " " of jsonpath input +ERROR: syntax error at or near " " of jsonpath input -- Should fail (not supported) SELECT * FROM JSON_TABLE(jsonb '{"a": 123}', '$' || '.' || 'a' COLUMNS (foo int)); ERROR: only string constants supported in JSON_TABLE path specification