pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: shammat@gmx.net
Cc: Alexander Korotkov <aekorotkov@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16828: duplicate results when using ** recursive expression in JSON path
Date: Sun, 17 Jan 2021 14:42:01 -0500
Message-ID: <231763.1610912521@sss.pgh.pa.us> (raw)
In-Reply-To: <16828-2b0229babfad2d8c@postgresql.org>
References: <16828-2b0229babfad2d8c@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> The following query 

>   select jsonb_path_query_array(col, '$.**.itemName')
>   from (
>     values ('{"items": [{"itemName": "a", "items": [{"itemName":
> "b"}]}]}'::jsonb)
>   ) as t(col) 

> returns ["a", "a", "b", "b"] but should return only ["a", "b"] as each value
> only appears once in the JSON value. 

jsonpath_exec.c is a muddle of undocumented code, but I think
I found where the duplication is occurring: in executeAnyItem(),
the first occurrence comes out while recursing down from the
executeItemOptUnwrapTarget call at line 1419 (as of HEAD), and then
the duplicate comes out while recursing down from the executeAnyItem
call at line 1439.  So I'd say that that logic for
"ignoreStructuralErrors" needs a rethink.  (BTW, why is half of this
code relying on cxt->ignoreStructuralErrors while the other half
receives a passed-down flag?  That seems like a recipe for bugs,
especially with the lack of commentary about the reason for it.)

Alexander, git blame says all this code is your fault ...

			regards, tom lane





view thread (3+ messages)  latest in thread

Message-ID: <231763.1610912521@sss.pgh.pa.us>
Permalink:  ../231763.1610912521@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/231763.1610912521@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, shammat@gmx.net, aekorotkov@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16828: duplicate results when using ** recursive expression in JSON path
  In-Reply-To: <231763.1610912521@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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