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 1lAINI-0000Oq-Ed for pgsql-admin@arkaria.postgresql.org; Thu, 11 Feb 2021 20:15:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lAINH-0003uX-DP for pgsql-admin@arkaria.postgresql.org; Thu, 11 Feb 2021 20:15:39 +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 1lAINH-0003uQ-67 for pgsql-admin@lists.postgresql.org; Thu, 11 Feb 2021 20:15:39 +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 1lAINF-0006jU-1T for pgsql-admin@postgresql.org; Thu, 11 Feb 2021 20:15:38 +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 11BKFZPi1484157; Thu, 11 Feb 2021 15:15:35 -0500 From: Tom Lane To: "David G. Johnston" cc: Wells Oliver , pgsql-admin Subject: Re: Table column vales to JSON object keys? In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Thu, 11 Feb 2021 13:13:02 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1484155.1613074535.1@sss.pgh.pa.us> Date: Thu, 11 Feb 2021 15:15:35 -0500 Message-ID: <1484156.1613074535@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Thursday, February 11, 2021, Wells Oliver wrote: >> Trying to go from a table like: >> >> g | e | angle | path >> ----+---+--------+---------------------- >> g1 | e1 | a1 | http://foo.com/a.mp4 >> g1 | e1 | a2 | http://foo.com/b.mp4 >> g1 | e1 | a3 | http://foo.com/c.mp4 >> >> To a table like this, with a column value per angle as a key. >> >> g | e | obj >> ----+---+--------------------------------------------------- >> ------------------------------------------ >> g1 | e1 | {"a1": "http://foo.com/a.mp4", "a2": "http://foo.com/b.mp4", >> "a3": "http://foo.com/c.mp4"} >> >> Can't quite get there. > How far can you get? I'm guessing something like SELECT g, e, json_object_agg(angle, path) FROM ... GROUP BY g, e would work, but haven't experimented. regards, tom lane