Patch bug: Fix jsonpath .* on Arrays
David E. Wheeler <david@justatheory.com>
From: "David E. Wheeler" <david@justatheory.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-06-04T16:07:00Z
Lists: pgsql-hackers
Attachments
- 0001-Fix-behavior-of-jsonpath-.-on-arrays.patch (application/octet-stream) patch 0001
Hackers,
The behavior of the .* jpiAnyKey jsonpath selector seems incorrect.
```
select jsonb_path_query('[1,2,3]', '$.*');
jsonb_path_query
------------------
(0 rows)
select jsonb_path_query('[1,2,3,{"b": [3,4,5]}]', '$.*');
jsonb_path_query
------------------
[3, 4, 5]
```
The first example might be expected, since .* is intended for object keys, but the handing of `jpiAnyKey` has a branch for unwrapping arrays. The second example, however, just seems weird: this is .*, not .**.
The attached patch fixes it by passing the next node to `executeAnyItem()` (via `executeItemUnwrapTargetArray()`) and then properly setting `jperOk` when `executeAnyItem()` finds values and there is no current (next) node.
I took this approach given what appears to be the intended behavior or $* on arrays in lax mode. However, I could see an argument that .* should not apply to arrays at all. If so, I can submit a new patch removing the branch that unwraps an array with .*.
Best,
David
Commits
-
Add more test coverage for jsonpath "$.*" with arrays
- 3a137ab7e575 18.0 landed