Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rL5qz-0065DS-76 for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Jan 2024 18:20:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rL5qx-007O36-U9 for pgsql-bugs@arkaria.postgresql.org; Wed, 03 Jan 2024 18:20:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rL5qx-007Nyo-Ky for pgsql-bugs@lists.postgresql.org; Wed, 03 Jan 2024 18:20:31 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rL5qv-00DZaO-2H for pgsql-bugs@lists.postgresql.org; Wed, 03 Jan 2024 18:20:30 +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 403IKR8I230222; Wed, 3 Jan 2024 13:20:27 -0500 From: Tom Lane To: Oscar van Baten cc: pgsql-bugs@lists.postgresql.org, David Rowley Subject: Re: Bugreport: incorrect result in 16.1 in query with string_agg(distinct+json_build_object In-reply-to: References: <210176.1704301004@sss.pgh.pa.us> Comments: In-reply-to Oscar van Baten message dated "Wed, 03 Jan 2024 19:01:20 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <230220.1704306027.1@sss.pgh.pa.us> Date: Wed, 03 Jan 2024 13:20:27 -0500 Message-ID: <230221.1704306027@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Oscar van Baten writes: > There you go: > GroupAggregate (cost=94.38..128.98 rows=200 width=96) > Output: a.id, string_agg(DISTINCT 'val_B'::text, ', '::text), > (json_agg(json_build_object('val_1', a.id, 'val_2', (SubPlan 1))))::text| Ah, that gave me the clue I needed (maybe I should have deduced it from your Subject, but I plead ENOCAFFEINE). Your query as submitted doesn't use DISTINCT in the STRING_AGG call, but that's needed to trigger the bug. And it is indeed the same bug as #18264: it begins at the same commit, and David's WIP patch fixes it. regards, tom lane