Re: BUG #16828: duplicate results when using ** recursive expression in JSON path - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #16828: duplicate results when using ** recursive expression in JSON path
Date
Msg-id 231763.1610912521@sss.pgh.pa.us
Whole thread Raw
In response to BUG #16828: duplicate results when using ** recursive expression in JSON path  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #16828: duplicate results when using ** recursive expression in JSON path
List pgsql-bugs
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



pgsql-bugs by date:

Previous
From:
Date:
Subject: RE: BUG #16825: When building on Windows, cl /? retrun 'x64' not AMD64 and the build does not create x64 environment
Next
From: Alexander Korotkov
Date:
Subject: Re: BUG #16828: duplicate results when using ** recursive expression in JSON path