mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Doc: improve documentation around jsonpath regular expressions.
Provide some documentation about the differences between XQuery
regular expressions and those supported by Spencer's regex engine.
Since SQL now exposes XQuery regexps with the LIKE_REGEX operator,
I made this a standalone section designed to help somebody who
has to translate a LIKE_REGEX query to Postgres. (Eventually we might
extend Spencer's engine to allow precise implementation of XQuery,
but not today.)
Reference that in the jsonpath docs, provide definitions of the
XQuery flag letters, and add a description of the JavaScript-inspired
string literal syntax used within jsonpath. Also point out explicitly
that backslashes used within like_regex patterns will need to be doubled.
This also syncs the docs with the decision implemented in commit
d5b90cd64
to desupport XQuery's 'x' flag for now.
Jonathan Katz and Tom Lane
Discussion: https://postgr.es/m/CAPpHfdvDci4iqNF9fhRkTqhe-5_8HmzeLt56drH%2B_Rv2rNRqfg@mail.gmail.com
This commit is contained in:
@ -666,13 +666,32 @@ SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @> '{"tags": ["qu
|
||||
</itemizedlist>
|
||||
|
||||
<para>
|
||||
An SQL/JSON path expression is an SQL character string literal,
|
||||
so it must be enclosed in single quotes when passed to an SQL/JSON
|
||||
query function. Following the JavaScript
|
||||
conventions, character string literals within the path expression
|
||||
must be enclosed in double quotes. Any single quotes within this
|
||||
character string literal must be escaped with a single quote
|
||||
by the SQL convention.
|
||||
An SQL/JSON path expression is typically written in an SQL query as an
|
||||
SQL character string literal, so it must be enclosed in single quotes,
|
||||
and any single quotes desired within the value must be doubled
|
||||
(see <xref linkend="sql-syntax-strings"/>).
|
||||
Some forms of path expressions require string literals within them.
|
||||
These embedded string literals follow JavaScript/ECMAScript conventions:
|
||||
they must be surrounded by double quotes, and backslash escapes may be
|
||||
used within them to represent otherwise-hard-to-type characters.
|
||||
In particular, the way to write a double quote within an embedded string
|
||||
literal is <literal>\"</literal>, and to write a backslash itself, you
|
||||
must write <literal>\\</literal>. Other special backslash sequences
|
||||
include those recognized in JSON strings:
|
||||
<literal>\b</literal>,
|
||||
<literal>\f</literal>,
|
||||
<literal>\n</literal>,
|
||||
<literal>\r</literal>,
|
||||
<literal>\t</literal>,
|
||||
<literal>\v</literal>
|
||||
for various ASCII control characters, and
|
||||
<literal>\u<replaceable>NNNN</replaceable></literal> for a Unicode
|
||||
character identified by its 4-hex-digit code point. The backslash
|
||||
syntax also includes two cases not allowed by JSON:
|
||||
<literal>\x<replaceable>NN</replaceable></literal> for a character code
|
||||
written with only two hex digits, and
|
||||
<literal>\u{<replaceable>N...</replaceable>}</literal> for a character
|
||||
code written with 1 to 6 hex digits.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
|
Reference in New Issue
Block a user