Q: Escapes in jsonpath Idents - Mailing list pgsql-hackers

From David E. Wheeler
Subject Q: Escapes in jsonpath Idents
Date
Msg-id 1EB17DF9-2636-484B-9DD0-3CAB19C4F5C4@justatheory.com
Whole thread Raw
Responses Re: Q: Escapes in jsonpath Idents
Re: Q: Escapes in jsonpath Idents
List pgsql-hackers
Hackers,

The jsonpath doc[1] has an excellent description of the format of strings, but for unquoted path keys, it simply says:

> Member accessor that returns an object member with the specified key. If the key name matches some named variable
startingwith $ or does not meet the JavaScript rules for an identifier, it must be enclosed in double quotes to make it
astring literal. 

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
identifierdiffers from a string in that a string is data, while an identifier is part of the code. In JavaScript, there
isno way to convert identifiers to strings, but sometimes it is possible to parse strings into identifiers. 


However, the Postgres parsing of jsonpath keys appears to follow the same rules as strings, allowing backslash escapes:

david=# select '$.fo\u00f8 == $x'::jsonpath;
     jsonpath       -------------------
 ($."foø" == $"x")

This would seem to contradict the documentation. Is this behavior required by the SQL standard? Do the docs need
updating?Or should the code actually follow the JSON identifier behavior? 

Thanks,

David

PS: Those excellent docs on strings mentions support for \v, but the grammar in the right nav of
https://www.json.org/json-en.htmldoes not. Another bonus feature? 

[1]: https://www.postgresql.org/docs/16/datatype-json.html#DATATYPE-JSONPATH
[2]: https://developer.mozilla.org/en-US/docs/Glossary/Identifier




pgsql-hackers by date:

Previous
From: "Andrey M. Borodin"
Date:
Subject: Re: UUID v7
Next
From: Andres Freund
Date:
Subject: Re: Vectored I/O in bulk_write.c