pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17440: not expected result from jsonb_path_query
2+ messages / 2 participants
[nested] [flat]

* BUG #17440: not expected result from jsonb_path_query
@ 2022-03-15 16:58 PG Bug reporting form <noreply@postgresql.org>
  2022-03-24 22:40 ` Re: BUG #17440: not expected result from jsonb_path_query Alexander Korotkov <aekorotkov@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2022-03-15 16:58 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: edouard.hibon@free.fr

The following bug has been logged on the website:

Bug reference:      17440
Logged by:          Edouard HIBON
Email address:      edouard.hibon@free.fr
PostgreSQL version: 14.0
Operating system:   windows 10
Description:        

Query 1 : SELECT jsonb_path_query('[1,2,3]' :: jsonb, '$') results in 1
value '[1,2,3]' :: jsonb as expected
Query 2 : SELECT jsonb_path_query('[1,2,3]' :: jsonb, '$[*]') results in a
set of 3 values '1', '2', '3' as expected
Query 3 : SELECT jsonb_path_query('[1,2,3]' :: jsonb, '$[*] ? (@ <> null)')
results in a set of 3 values '1', '2', '3' as expected
Query 4 : SELECT jsonb_path_query('[1,2,3]' :: jsonb, '$ ? (@ <> null)')
results in a set of 3 values '1', '2', '3' as for the queries 2 & 3 whereas
I would expect only one value '[1,2,3]' as for the query 1 because there is
no member accessor nor array element accessor in this jsonpath, and @ should
represent the initial jsonb value being queried $

demo :
https://dbfiddle.uk/?rdbms=postgres_14&fiddle=f09164502df5ee1bb620057689e6f810



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #17440: not expected result from jsonb_path_query
  2022-03-15 16:58 BUG #17440: not expected result from jsonb_path_query PG Bug reporting form <noreply@postgresql.org>
@ 2022-03-24 22:40 ` Alexander Korotkov <aekorotkov@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Alexander Korotkov @ 2022-03-24 22:40 UTC (permalink / raw)
  To: edouard.hibon@free.fr, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

Hi!

On Tue, Mar 15, 2022 at 8:34 PM PG Bug reporting form
<noreply@postgresql.org> wrote:
> The following bug has been logged on the website:
>
> Bug reference:      17440
> Logged by:          Edouard HIBON
> Email address:      edouard.hibon@free.fr
> PostgreSQL version: 14.0
> Operating system:   windows 10
> Description:
>
> Query 1 : SELECT jsonb_path_query('[1,2,3]' :: jsonb, '$') results in 1
> value '[1,2,3]' :: jsonb as expected
> Query 2 : SELECT jsonb_path_query('[1,2,3]' :: jsonb, '$[*]') results in a
> set of 3 values '1', '2', '3' as expected
> Query 3 : SELECT jsonb_path_query('[1,2,3]' :: jsonb, '$[*] ? (@ <> null)')
> results in a set of 3 values '1', '2', '3' as expected
> Query 4 : SELECT jsonb_path_query('[1,2,3]' :: jsonb, '$ ? (@ <> null)')
> results in a set of 3 values '1', '2', '3' as for the queries 2 & 3 whereas
> I would expect only one value '[1,2,3]' as for the query 1 because there is
> no member accessor nor array element accessor in this jsonpath, and @ should
> represent the initial jsonb value being queried $
>
> demo :
> https://dbfiddle.uk/?rdbms=postgres_14&fiddle=f09164502df5ee1bb620057689e6f810

The default jsonpath mode is lax.  Lax mode automatically unwraps
arrays.  Unwrapping array in filter affects the result value as well.
Strict mode works as you expected.

SELECT jsonb_path_query('[1,2,3]' :: jsonb, 'strict $ ? (@ <> null)')
[1, 2, 3]

My personal opinion is that lax mode is generally prone to
javascript-style weirdness, and one should always use strict.

------
Regards,
Alexander Korotkov





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2022-03-24 22:40 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-03-15 16:58 BUG #17440: not expected result from jsonb_path_query PG Bug reporting form <noreply@postgresql.org>
2022-03-24 22:40 ` Alexander Korotkov <aekorotkov@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox