Re: Patch bug: Fix jsonpath .* on Arrays - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: Patch bug: Fix jsonpath .* on Arrays
Date
Msg-id CAKFQuwb=tJMm0NEn3NDVtzfaoNs73rcf3gbss7E5J9Lvns=y2w@mail.gmail.com
Whole thread Raw
In response to Patch bug: Fix jsonpath .* on Arrays  ("David E. Wheeler" <david@justatheory.com>)
Responses Re: Patch bug: Fix jsonpath .* on Arrays
List pgsql-hackers
On Tuesday, June 4, 2024, David E. Wheeler <david@justatheory.com> wrote:
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 .**.

This seems to be working correctly. Lax mode causes the first array level to unwrap and produce new context item values.  Then the wildcard member accessor is applied to each.  Numbers don’t have members so no matches exist in the first example.  The object in the second indeed has a single member and so matches the wildcard and its value, the array, is returned.

David J.

pgsql-hackers by date:

Previous
From: "David E. Wheeler"
Date:
Subject: Patch bug: Fix jsonpath .* on Arrays
Next
From: Wolfgang Walther
Date:
Subject: Re: Build with LTO / -flto on macOS