Re: Q: Escapes in jsonpath Idents

David E. Wheeler <david@justatheory.com>

From: "David E. Wheeler" <david@justatheory.com>
To: Peter Eisentraut <peter@eisentraut.org>
Cc: Erik Wienhold <ewie@ewie.name>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2024-04-24T11:52:37Z
Lists: pgsql-hackers
On Apr 24, 2024, at 05:51, Peter Eisentraut <peter@eisentraut.org> wrote:

>    A <JSON path identifier> is classified as follows.
> 
>    Case:
> 
>    a) A <JSON path identifier> that is a <dollar sign> is a <JSON path
>       context variable>.
> 
>    b) A <JSON path identifier> that begins with <dollar sign> is a
>       <JSON path named variable>.
> 
>    c) Otherwise, a <JSON path identifier> is a <JSON path key name>.
> 
> Does this help?  I wasn't following all the discussion to see if there is anything wrong with the implementation.

Yes, it does, as it ties the special meaning of the dollar sign to the *beginning* of an expression. So it makes sense that this would be an error:

david=# select '$.$foo'::jsonpath;
ERROR: syntax error at or near "$foo" of jsonpath input
LINE 1: select '$.$foo'::jsonpath;
               ^

But I’m less sure when a dollar sign is used in the *middle* (or end) of a json path identifier:

david=# select '$.xx$foo'::jsonpath;
ERROR:  syntax error at or near "$foo" of jsonpath input
LINE 1: select '$.xx$foo'::jsonpath;
               ^

Perhaps that should be valid?

Best,

David




Commits

  1. doc: Correct jsonpath string literal escapes description