Re: BUG #16828: duplicate results when using ** recursive expression in JSON path

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: shammat(at)gmx(dot)net
Cc: Alexander Korotkov <aekorotkov(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16828: duplicate results when using ** recursive expression in JSON path
Date: 2021-01-17 19:42:01
Message-ID: 231763.1610912521@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alexander Korotkov 2021-01-17 21:24:19 Re: BUG #16828: duplicate results when using ** recursive expression in JSON path
Previous Message robionekenobi 2021-01-17 18:22:00 RE: BUG #16825: When building on Windows, cl /? retrun 'x64' not AMD64 and the build does not create x64 environment