The following bug has been logged on the website:
Bug reference: 18510
Logged by: Lex Vorona
Email address: voronaam@gmail.com
PostgreSQL version: 16.3
Operating system: Linux (Ubuntu)
Description:
Note that JSONPATH documentation states [1]:
> to write a backslash itself, you must write \\
It works for a backslash as long as it is not the last character in the
input string.
Simplest way to reproduce:
psql (16.3 (Ubuntu 16.3-1.pgdg22.04+1))
postgres=# select '$.field ? (@ like_regex "a\\b")'::jsonpath; -- works
jsonpath
---------------------------------
$."field"?(@ like_regex "a\\b")
(1 row)
postgres=# select '$.field ? (@ like_regex "a\\")'::jsonpath; -- does not
work
ERROR: invalid regular expression: invalid escape \ sequence
LINE 1: select '$.field ? (@ like_regex "a\\")'::jsonpath;
^
Also reproducible with functions like jsonb_path_exists(...) which
automatically cast parameters to jsonpath.
1:
https://www.postgresql.org/docs/current/datatype-json.html#DATATYPE-JSONPATH