BUG #17694: In JSONPath expressions, characters between leading $ and dot appear to be ignored

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: david(at)justatheory(dot)com
Subject: BUG #17694: In JSONPath expressions, characters between leading $ and dot appear to be ignored
Date: 2022-11-23 20:11:04
Message-ID: 17694-2f7d9576ae277d64@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17694
Logged by: David Wheeler
Email address: david(at)justatheory(dot)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"';
```

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2022-11-24 05:31:33 Bug in jsonb_path_exists (maybe _match) one-element scalar/variable jsonpath handling
Previous Message Greg Stark 2022-11-23 19:13:56 Re: BUG #17693: Slow performance: Much slower queries on pg_stat_all_tables since 13.4