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 1fKntN-0008Fy-4x for pgsql-general@arkaria.postgresql.org; Mon, 21 May 2018 16:42:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fKntL-00011n-Gc for pgsql-general@arkaria.postgresql.org; Mon, 21 May 2018 16:42:35 +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 1fKntL-00011d-9F for pgsql-general@lists.postgresql.org; Mon, 21 May 2018 16:42:35 +0000 Received: from mx.nsu.ru ([84.237.50.39]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fKntE-00032H-Kz for pgsql-general@postgresql.org; Mon, 21 May 2018 16:42:34 +0000 Received: from Debian-exim by mx.nsu.ru with local (Exim 4.72) (envelope-from ) id 1fKntC-0004w2-11 for pgsql-general@postgresql.org; Mon, 21 May 2018 23:42:26 +0700 Received: from [84.237.50.47] (helo=regency.nsu.ru) by mx.nsu.ru with esmtp (Exim 4.72) (envelope-from ) id 1fKntB-0004vf-Sn; Mon, 21 May 2018 23:42:25 +0700 Received: from regency.nsu.ru (localhost [127.0.0.1]) by regency.nsu.ru (8.14.2/8.14.2) with ESMTP id w4LH1IB6008514; Mon, 21 May 2018 23:01:19 +0600 (NOVT) (envelope-from danfe@regency.nsu.ru) Received: (from danfe@localhost) by regency.nsu.ru (8.14.2/8.14.2/Submit) id w4LH1DZd008481; Tue, 22 May 2018 00:01:13 +0700 (+07) (envelope-from danfe) Date: Tue, 22 May 2018 00:01:13 +0700 From: Alexey Dokuchaev To: Tom Lane Cc: "David G. Johnston" , pgsql-general Subject: Re: Aggregate functions with FROM clause and ROW_COUNT diagnostics Message-ID: <20180521170113.GA6259@regency.nsu.ru> References: <20180521125441.GA85087@regency.nsu.ru> <30939.1526913927@sss.pgh.pa.us> <20180521162831.GA97361@regency.nsu.ru> <5595.1526919652@sss.pgh.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5595.1526919652@sss.pgh.pa.us> User-Agent: Mutt/1.4.2.1i X-KLMS-Rule-ID: 3 X-KLMS-Message-Action: skipped X-KLMS-AntiSpam-Status: not scanned, whitelist X-KLMS-AntiPhishing: not scanned, whitelist X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server, version 8.0.1.705, not scanned, whitelist List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, May 21, 2018 at 12:20:52PM -0400, Tom Lane wrote: > 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 ... Bingo! Thanks Tom, you're the best (as always). Quick reality check question: are count(*) vs. count(_) equivalent above? I vaguely recall that count(1) got somewhat slower than count(*) after 8.2, but cannot back it up right now. ./danfe