Document that jsonpath == can be used as ANY

Started by Marcos Pegoraro2 months ago5 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253452
psql -h localhost -U postgres

Built from patchset v1 (message #1), October 23, 2026 at 07:08 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t253452_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t253452_1 && git checkout t253452_1

Patchset v1 (message #1) is on t253452_1

Jump to latest
#1Marcos Pegoraro
marcos@f10.com.br

Additional example of == operator being used like ANY

regards
Marcos

Attachments:

t253452_1
jsonpath_equals.patchapplication/octet-stream; name=jsonpath_equals.patchDownload+4-1
#2Marcos Pegoraro
marcos@f10.com.br
In reply to: Marcos Pegoraro (#1)
Re: Document that jsonpath == can be used as ANY

Em seg., 17 de ago. de 2026 às 09:04, Marcos Pegoraro <marcos@f10.com.br>
escreveu:

Additional example of == operator being used like ANY

I insist on this, there is no documentation on how to find an array of
values in a JSON object.

select jsonb_path_query_array('[5,6,7,8,9]', '$[*] ? (@ == $arr)','{"arr":
[2,5,8]}')
-------
[5, 8]

regards
Marcos

#3David G. Johnston
david.g.johnston@gmail.com
In reply to: Marcos Pegoraro (#2)
Re: Document that jsonpath == can be used as ANY

On Wed, Sep 30, 2026 at 11:48 AM Marcos Pegoraro <marcos@f10.com.br> wrote:

Em seg., 17 de ago. de 2026 às 09:04, Marcos Pegoraro <marcos@f10.com.br>
escreveu:

Additional example of == operator being used like ANY

I insist on this, there is no documentation on how to find an array of
values in a JSON object.

select jsonb_path_query_array('[5,6,7,8,9]', '$[*] ? (@ == $arr)','{"arr":
[2,5,8]}')
-------
[5, 8]

I feel like simply including an example here is insufficient. There isn't
anything special about == going on here; you can substitute >= and get a
valid result. I don't mind the example but this entire behavior of value
== value when the lefthand value is scalar and the righthand value is an
array (maybe object?) appears undefined. The sentence there - "(this, and
the other comparison operators, work on all JSON scalar values)" - in fact
implies that the array version shouldn't work.

David J.

#4Marcos Pegoraro
marcos@f10.com.br
In reply to: David G. Johnston (#3)
Re: Document that jsonpath == can be used as ANY

Em qua., 30 de set. de 2026 às 16:14, David G. Johnston <
david.g.johnston@gmail.com> escreveu:

I feel like simply including an example here is insufficient. There isn't
anything special about == going on here;

Yes, I agree that an example only is insufficient.
But the behavior of == is indeed different when it's an array or a scalar
value.
It will only work as an array only if assigned to a parameter, and a scalar
works the same way for both.

regards
Marcos

#5David G. Johnston
david.g.johnston@gmail.com
In reply to: Marcos Pegoraro (#4)
Re: Document that jsonpath == can be used as ANY

On Wed, Sep 30, 2026 at 1:22 PM Marcos Pegoraro <marcos@f10.com.br> wrote:

Em qua., 30 de set. de 2026 às 16:14, David G. Johnston <
david.g.johnston@gmail.com> escreveu:

I feel like simply including an example here is insufficient. There
isn't anything special about == going on here;

Yes, I agree that an example only is insufficient.
But the behavior of == is indeed different when it's an array or a scalar
value.
It will only work as an array only if assigned to a parameter, and a
scalar works the same way for both.

Apparently this is a side-effect of lax mode:

select jsonb_path_query_array(
'[5,6,7,8,9]',
'strict $[*] ? (@ == $arr)',
'{"arr": [2,5,8]}'
);

produces and empty array: []

So I like the example only patch even less as it doesn't explain at all why
that random example has been included or how/why it works.

Maybe move the example and exposition to 19.6.2.2 ?

David J.