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 1p7GRs-0007RJ-Ab for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Dec 2022 13:44:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p7GRp-0000im-Sy for pgsql-hackers@arkaria.postgresql.org; Mon, 19 Dec 2022 13:44:53 +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 1p7GRp-0000h1-I0 for pgsql-hackers@lists.postgresql.org; Mon, 19 Dec 2022 13:44:53 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p7GRn-0007OE-Bg for pgsql-hackers@postgresql.org; Mon, 19 Dec 2022 13:44:52 +0000 Received: by mail-pl1-x632.google.com with SMTP id t2so9072595ply.2 for ; Mon, 19 Dec 2022 05:44:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=TUqvl9Xcn2blrUHVlpocltt8aObJtzTMJfRrM16DV5E=; b=q46LRCCz2DCiidAD9o3xmFsXgoEleoO/fh+ms+URwOI+wdqaZzYWU+7QTsFnNYJY58 JiGL1XYiU++2mpiFE/9k7E1b0PHolO7KRV6IEj3sX70bPRBTt0i7a+sUBd0kFEjYwfty htoVfT+eLmaYlxldvPTGrUBKrLBbIjpq7sROk18XMEadEnwhQHoIN4sqoxSoCB8kewpd QDk50+QX0mqrQ49fcHUQjZRxAQNl2Si3HNXd0Or6yeF4LkAbhnalYOopLlpF6Qs9NrV5 1LNL8FxZSel2gctIkxM6DD/Bfz6W6EzG3zZpNzUHqhZla3v9UZJ1tguAtuM9f/2RikYT 4fgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TUqvl9Xcn2blrUHVlpocltt8aObJtzTMJfRrM16DV5E=; b=ZH3yyrR2LD7Z2pFag6UxT+fZ74hjXmpkeD/2MHdL2HCTJF/ea2zzzYg3IZC9Lz+hcE N1znai+GmCtxh6EDobgHMdSvOILTQlDZ+TyrUWgWJsT+R2jccfU76nd+Nt4jIZmzoK3C C57UzwvI2svHfoLIwbsPJPBowq9cG3QSFuPVpdsR7yS79MHcqDPH3GUIMjb4aXCkQf2J qAM4NbLzeScaDyGezSPFtHQHiE1Kty9/aOkgLAseU9+ctM0kRWSLt0dCWA7XldsVEGG4 5dpzOJJmzu/WQ7N27UQwT0XALO3zddvOx6qsWDVhkRyp0DtMy9YVDxIQ/dl3kTmgy0Zo 5lKw== X-Gm-Message-State: ANoB5pmqipPY/jRhsZcG6ttjYQIxs0VKkEGvCQNhV7uTRy7aYJuSnpR/ M/j8dBWcb3OAedDCfuYSrXtwZQ3vJQfmOt/NY0k= X-Google-Smtp-Source: AA0mqf73ODRdV8P4w9AO24WKLqSRVs5h0RFhN8DplgCvCAG6aaNVUbQ6auwqtk1jm9IxFQ09TjFypOuF/JAqKRZAf2k= X-Received: by 2002:a17:902:8698:b0:188:e255:39af with SMTP id g24-20020a170902869800b00188e25539afmr80734377plo.86.1671457490200; Mon, 19 Dec 2022 05:44:50 -0800 (PST) MIME-Version: 1.0 References: <835590.1671424214@sss.pgh.pa.us> In-Reply-To: <835590.1671424214@sss.pgh.pa.us> From: Isaac Morland Date: Mon, 19 Dec 2022 08:44:39 -0500 Message-ID: Subject: Re: GROUP BY ALL To: Tom Lane Cc: Andrey Borodin , pgsql-hackers Content-Type: multipart/alternative; boundary="000000000000f5f9ff05f02e8505" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000f5f9ff05f02e8505 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, 18 Dec 2022 at 23:30, Tom Lane wrote: > Andrey Borodin writes: > > I saw a thread in a social network[0] about GROUP BY ALL. The idea seem= s > useful. > > Isn't that just a nonstandard spelling of SELECT DISTINCT? > In a pure relational system, yes; but since Postgres allows duplicate rows, both in actual table data and in intermediate and final result sets, no. Although I'm pretty sure no aggregates other than count() are useful - any other aggregate would always just combine count() copies of the duplicated value in some way. What would happen if there are aggregate functions in the tlist? > I'm not especially on board with "ALL" meaning "ALL (oh, but not > aggregates)". > The requested behaviour can be accomplished by an invocation something like= : select (t).*, count(*) from (select (=E2=80=A6field1, field2, =E2=80=A6) as= t from =E2=80=A6tables=E2=80=A6) s group by t; So we collect all the required fields as a tuple, group by the tuple, and then unpack it into separate columns in the outer query. --000000000000f5f9ff05f02e8505 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, 18 Dec 2022 at 23:30, Tom Lane &l= t;tgl@sss.pgh.pa.us> wrote:
=
--000000000000f5f9ff05f02e8505--