Q: Escapes in jsonpath Idents

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Q: Escapes in jsonpath Idents
Date: 2024-03-16 18:39:20
Message-ID: 1EB17DF9-2636-484B-9DD0-3CAB19C4F5C4@justatheory.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 starting with $ or does not meet the JavaScript rules for an identifier, it must be enclosed in double quotes to make it a string 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 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.

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.html does 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2024-03-16 19:10:14 Re: Vectored I/O in bulk_write.c
Previous Message Andrey M. Borodin 2024-03-16 17:43:54 Re: UUID v7