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 1v2ArG-0013KQ-Vg for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Sep 2025 15:59:42 +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 1v2ArE-003YKN-Mb for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Sep 2025 15:59:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v2ArE-003YKE-DJ for pgsql-hackers@lists.postgresql.org; Fri, 26 Sep 2025 15:59:41 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v2ArC-000FbN-2b for pgsql-hackers@postgresql.org; Fri, 26 Sep 2025 15:59:40 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-b29e8a3e453so322377666b.0 for ; Fri, 26 Sep 2025 08:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pgguru-net.20230601.gappssmtp.com; s=20230601; t=1758902377; x=1759507177; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UbGJEV6pahgxoVoDDIThjjJm1SeTltptbpcTBmDPpic=; b=hPLVIkciB29QrDxZs+IWIIGXD+fxuL+6OHcXbImkUJ0u+nO3aky4mhoZ2IzA+EDvQT 4A4xgavmpzxqoMGJpCzRhlUCcAy5meWTHdT0M7XDKaRMMI/HZ2pD6Lx/Gs7a0FGCdX7R D35GCZ1wmdAo/Utsi+x7Nj+7hbzkUSiVilkLlhGZL4IGWNRt9xtL5oSem3n2kfpTzpCV hVAT9WXPdL5OwHhKTEayhhxSptAorWVSMncsj8ANMnaobrFaRHxA3dJAQswZkU/cVWJ9 Fdo+/Jf/AptP6QnfdGNA633lpqqrxHbyw6fi3q3o4vBewV/DzQzeLxBkTZ8Rwvg6Rw/u Ee+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758902377; x=1759507177; h=content-transfer-encoding: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=UbGJEV6pahgxoVoDDIThjjJm1SeTltptbpcTBmDPpic=; b=hav8+yBB9+wTmzY/nNBcr8t++i4cXri3NR0Tt6kct1R1Tre7fK5WZHWXVDZ+ugDwUT bFLM2reNRbE03SKw/vD8E7QxfGcCMQhcB5k9YNmUDvdJjr5OnQutGNkYAtgLBCTuYjIf UZhokrTZhydjSZgtQBKzUYJuFhWRriYxUHHFZwTDFuOH5dZFvD0Vdq78cpXnOVIPHWEq jF2GF8bx4E96ofwD0LspajzYy3vjl4eQGBRw3OhWlRPowHUHsBY5ILabpC2iTM2Wse8J KrUiYcygXxeNMeP8T7mlaAuBpmcsnJ15aDSqd6mGYvL0Cuvj3ysigQuEVE6306HMfoXw eHPQ== X-Forwarded-Encrypted: i=1; AJvYcCWsAZUPpBY7f/urmQGLXPNDHqIEIHs66u3kZRfb8zZP7CexQk9OD4+A5up7Vgi/QqtHESVQeLtA9ZMVvsZg@postgresql.org X-Gm-Message-State: AOJu0YwfW+jkoq2pPpA7NTwHQmGBeGRXzg4Jlp+8A66iUrUp9JRRmzsk n1wkLIlcb2tAbAC5zlsIE31DQi4XxzlGgt9n1LFEclzESOT4JtWe5KPNAuqiP2Z1VV05qIBy+NT WppZaLSEucL0dqdRb4tSId3OoCO9Py7qR7fSesqVi3Q== X-Gm-Gg: ASbGnct34HFSbbWroesT22pxmcHnQsFwz6Irg6dUuiko/eJuAhEFfLK0N+/ItzImJVG zcjBWA2tWYGaIxkzSOFiIdS9nypPmEBg8txKRrajcUI98GULUmOsR4W3eBKOf8Cm1oPXE+mabDs Gz1JPHwuZQgVgkw+JaKrXl4sY5ou27QWsOl5BQhWzFD1eDHckzi1GWQjo6D5QR/ZbjOwm+oAP93 RECOoApABfNscX9j6oKKRH1GZqAv7lBebW0MfzmrQ== X-Google-Smtp-Source: AGHT+IHsDCw79l30oKJ3ufMYNwImaRykivkZy4yh/BenBrHM0lPtOS/2gcFBXSphvIwXFGpp5RUORUNDHp+dfQ8iX2w= X-Received: by 2002:a17:906:586:b0:b2e:4504:2cee with SMTP id a640c23a62f3a-b34d0381c5emr754028566b.41.1758902377369; Fri, 26 Sep 2025 08:59:37 -0700 (PDT) MIME-Version: 1.0 References: <931747.1721687375@sss.pgh.pa.us> <634aca95-6db5-4beb-b18d-67e65582817f@eisentraut.org> <4054709.1758895915@sss.pgh.pa.us> <3d01eb20-d587-4dec-9261-0c92240ce546@eisentraut.org> In-Reply-To: <3d01eb20-d587-4dec-9261-0c92240ce546@eisentraut.org> From: David Christensen Date: Fri, 26 Sep 2025 10:59:26 -0500 X-Gm-Features: AS18NWAr5FZdN-8gAQbfzDEDJi0mWOF2GpbAjJu2CkNUK6TMeICgJedbViS_j1U Message-ID: Subject: Re: [PATCH] GROUP BY ALL To: Peter Eisentraut Cc: Tom Lane , pgsql-hackers , "David G. Johnston" , Jelte Fennema-Nio Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Sep 26, 2025 at 10:54=E2=80=AFAM Peter Eisentraut wrote: > > On 26.09.25 16:11, Tom Lane wrote: > > Peter Eisentraut writes: > >> The initially proposed patch appears to have the right idea overall. > >> But it does not handle more complex cases like > >> SELECT a, SUM(b)+a FROM t1 GROUP BY ALL; > > > >> (For explanation: GROUP BY ALL expands to all select list entries tha= t > >> do not contain aggregates. So the above would expand to > >> SELECT a, SUM(b)+a FROM t1 GROUP BY a; > >> which should then be rejected based on the existing rules.) > > > > I thought I understood this definition, up till your last > > comment. What's invalid about that expanded query? > > > > regression=3D# create table t1 (a int, b int); > > CREATE TABLE > > regression=3D# SELECT a, SUM(b)+a FROM t1 GROUP BY a; > > a | ?column? > > ---+---------- > > (0 rows) > > This was a sloppy example. Here is a better one: > > create table t1 (a int, b int, c int); > > select a, sum(b)+c from t1 group by all; > > This is equivalent to > > select a, sum(b)+c from t1 group by a; > > which would be rejected as > > ERROR: column "t1.c" must appear in the GROUP BY clause or be used > in an aggregate function Verified that with v2 that this is what happens in this case; will include this and whatever other feedback there is in a v3.