Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fKnYr-0006vA-FU for pgsql-general@arkaria.postgresql.org; Mon, 21 May 2018 16:21:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fKnYp-0001U5-Em for pgsql-general@arkaria.postgresql.org; Mon, 21 May 2018 16:21:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fKnYp-0001Tv-6s for pgsql-general@lists.postgresql.org; Mon, 21 May 2018 16:21:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fKnYm-0002a2-8u for pgsql-general@postgresql.org; Mon, 21 May 2018 16:21:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w4LGKqad005596; Mon, 21 May 2018 12:20:52 -0400 From: Tom Lane To: Alexey Dokuchaev cc: "David G. Johnston" , pgsql-general Subject: Re: Aggregate functions with FROM clause and ROW_COUNT diagnostics In-reply-to: <20180521162831.GA97361@regency.nsu.ru> References: <20180521125441.GA85087@regency.nsu.ru> <30939.1526913927@sss.pgh.pa.us> <20180521162831.GA97361@regency.nsu.ru> Comments: In-reply-to Alexey Dokuchaev message dated "Mon, 21 May 2018 23:28:31 +0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5594.1526919652.1@sss.pgh.pa.us> Date: Mon, 21 May 2018 12:20:52 -0400 Message-ID: <5595.1526919652@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alexey Dokuchaev writes: > On Mon, May 21, 2018 at 10:45:27AM -0400, Tom Lane wrote: >> OP could do something like >> select json_agg(_) as j, count(*) as c INTO r FROM ( > Thanks, I've arrived at the same solution (using local RECORD) eventually. > It works as intended, but I still need to assign OUT parameters by hand: > retcode := tmp.c; > result := tmp.j; Actually, it should work to do select json_agg(_), count(*) INTO result, retcode FROM ... regards, tom lane