Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1DwG-0004x3-Tm for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Jan 2021 19:42:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l1DwE-0005wu-NT for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Jan 2021 19:42:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1DwE-0005v2-HQ for pgsql-bugs@lists.postgresql.org; Sun, 17 Jan 2021 19:42:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1Dw7-0007NX-Ab for pgsql-bugs@lists.postgresql.org; Sun, 17 Jan 2021 19:42:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 10HJg1CP231764; Sun, 17 Jan 2021 14:42:02 -0500 From: Tom Lane To: shammat@gmx.net cc: Alexander Korotkov , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16828: duplicate results when using ** recursive expression in JSON path In-reply-to: <16828-2b0229babfad2d8c@postgresql.org> References: <16828-2b0229babfad2d8c@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sun, 17 Jan 2021 10:34:50 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <231761.1610912521.1@sss.pgh.pa.us> Date: Sun, 17 Jan 2021 14:42:01 -0500 Message-ID: <231763.1610912521@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form 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