Re: JSON/SQL: jsonpath: incomprehensible error message

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Erik Rijkers <er(at)xs4all(dot)nl>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: JSON/SQL: jsonpath: incomprehensible error message
Date: 2022-06-29 13:00:50
Message-ID: CAA4eK1+uWeL6m0VRXimDJWi7BvPkMDWs-0j4wcLjY7EXQ3Hpug@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jun 27, 2022 at 8:46 PM Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
>
> 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(at)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,
>

I guess it is okay to backpatch unless we think some user will be
dependent on such a message or there could be other side effects of
removing this. One thing that is not clear to me is why OP sees an
acceptable message (ERROR: syntax error, unexpected invalid token at
or near "=" of jsonpath input) for a similar query in 14?

--
With Regards,
Amit Kapila.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2022-06-29 13:09:42 Re: Export log_line_prefix(); useful for emit_log_hook.
Previous Message Jonathan S. Katz 2022-06-29 12:57:10 Re: PostgreSQL 15 beta 2 release announcement draft