Re: Q: Escapes in jsonpath Idents
David E. Wheeler <david@justatheory.com>
From: "David E. Wheeler" <david@justatheory.com>
To: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2024-03-16T20:33:09Z
Lists: pgsql-hackers
On Mar 16, 2024, at 14:39, David E. Wheeler <david@justatheory.com> wrote:
> I went looking for the JavaScript rules for an identifier and found this in the MDN docs[2]:
>
>> In JavaScript, identifiers can contain Unicode letters, $, _, and digits (0-9), but may not start with a digit. An identifier differs from a string in that a string is data, while an identifier is part of the code. In JavaScript, there is no way to convert identifiers to strings, but sometimes it is possible to parse strings into identifiers.
Coda: Dollar signs don’t work at all outside double-quoted string identifiers:
david=# select '$.$foo'::jsonpath;
ERROR: syntax error at or near "$foo" of jsonpath input
LINE 1: select '$.$foo'::jsonpath;
^
david=# select '$.f$oo'::jsonpath;
ERROR: syntax error at or near "$oo" of jsonpath input
LINE 1: select '$.f$oo'::jsonpath;
^
david=# select '$."$foo"'::jsonpath;
jsonpath
----------
$."$foo"
This, too, contradicts the MDM definition an identifier (and some quick browser tests).
Best,
David
Commits
-
doc: Correct jsonpath string literal escapes description
- a8457887c3c1 12.19 landed
- b51dff73fa73 13.15 landed
- 630ed7ec4d36 14.12 landed
- feb19bf5081f 15.7 landed
- a7ed15f3ab81 16.3 landed
- b279e37015bb 17.0 landed