BUG #17694: In JSONPath expressions, characters between leading $ and dot appear to be ignored - Mailing list pgsql-bugs

From PG Bug reporting form
Subject BUG #17694: In JSONPath expressions, characters between leading $ and dot appear to be ignored
Date
Msg-id 17694-2f7d9576ae277d64@postgresql.org
Whole thread Raw
Responses Re: BUG #17694: In JSONPath expressions, characters between leading $ and dot appear to be ignored
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      17694
Logged by:          David Wheeler
Email address:      david@justatheory.com
PostgreSQL version: 15.1
Operating system:   macOS
Description:

The correct way to specify an absolute JSON path expression is to start with
`$.`, as in:

```
david=# select '{"foo": 1}' @? '$.foo';
 ?column? 
----------
 t
```

If, however, you omit the dot (`.`), the expression incorrectly always
evaluates to true!

```
david=# select '{"foo": 1}' @? '$foo';
 ?column? 
----------
 t

david=# select '{"foo": 1}' @? '$"foo bar"';
 ?column? 
----------
 t

david=# select '{"foo": 1}' @? '$"foo bar".bar';
 ?column? 
----------
 f
```

It looks like the text between the `$` and `.` is ignored. I don't think
this is right. Shouldn't it be a syntax error? Seems to properly complain if
using the same pattern in subpaths:

```
david=# select '{"foo": 1}' @? '$.foo"foo bar"';
ERROR:  syntax error at or near """ of jsonpath input
LINE 1: select '{"foo": 1}' @? '$.foo"foo bar"';
```


pgsql-bugs by date:

Previous
From: Greg Stark
Date:
Subject: Re: BUG #17693: Slow performance: Much slower queries on pg_stat_all_tables since 13.4
Next
From: "David G. Johnston"
Date:
Subject: Bug in jsonb_path_exists (maybe _match) one-element scalar/variable jsonpath handling