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 1qJEDc-0002uk-3h for pgsql-docs@arkaria.postgresql.org; Tue, 11 Jul 2023 14:19: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 1qJEDa-0004Jj-Ss for pgsql-docs@arkaria.postgresql.org; Tue, 11 Jul 2023 14:19:54 +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 1qJEDa-0004JX-FB for pgsql-docs@lists.postgresql.org; Tue, 11 Jul 2023 14:19:54 +0000 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qJEDX-003HFD-LA for pgsql-docs@lists.postgresql.org; Tue, 11 Jul 2023 14:19:53 +0000 Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2b6ff1ada5dso91934081fa.2 for ; Tue, 11 Jul 2023 07:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20221208.gappssmtp.com; s=20221208; t=1689085190; x=1691677190; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=r7RCtmGevvKAwEzLaaiKbHeWSgpdfccGm42PrzsAgvA=; b=I1KTvD7GN2IOHXCFuyuuIesmHgBuMSzaxQjcSTnFI032HPwD9F8FnW1PF6ij5G26o6 3+EA7QdT6IcWSNIGiF1/MwmV8hNb+lnr1NaHLA+nhOOeGdX5YO5bWga3hrehhYagihrs 2cR8fQjWzHweFOAS9Hbt/qpfECKAEk1XE8BUMzESNQiV/YVqTpsJkAEK/OTeDP52i0Kg 5LhWeajqsf5gGO5ZrBnUd2cMVsHXS5Ri9VgHEDRwJK103AkW5LIAjQ4/2slDkQeGy5Ay A9Lzz9oRMfD9NTY16V7otJMSiBrdP1E8i4y452tncd4s80PiE5eGz3tgpuvYTc73od2a OLbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689085190; x=1691677190; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=r7RCtmGevvKAwEzLaaiKbHeWSgpdfccGm42PrzsAgvA=; b=Qfb0Odt/E4SZYFlrfJsrgPno7+2wQWbDs7ZbDsq+d2jngs/L/V5mElDNzaneRke8n2 xe4C9jtQTOGe1E6eBsMumN2y8Zc8SOljBSzebsZ8BNvGd4oHoTWYaF8Ul2l/WWQvZXYm 3IMZlCjda1Aji4xLRAQ1rNM9Y1dcpEizebnTm79ZtJc1VGcv5o3dHclrkTQsvcD9tl0H TIQGEfTqobJAb3V6117P5UKSGWVVNUn1pn23yfuY5sqZn5awkpcg/pjpVoI9/gBif0hB KmQE/qG9RjWbpoXqpZ3PrcO12zPWLsw7Laq4k9hGrdO4JTNrWwsJpNkm631b9/AC4nzo cp8Q== X-Gm-Message-State: ABy/qLaxw/Lj+dKtyjPoglWrvFAC+VNMojbJb30r+djXcG5JDFCvF22H ibVm5m4L7J1gDxm1gM23LREseg== X-Google-Smtp-Source: APBJJlFPMAahC2RFeHOxe6pOZRk7hh77+YnLf6Z7FoFZByasHICpnC+3a4M04fI+eLi2bFDufxZdzA== X-Received: by 2002:a2e:2405:0:b0:2b6:df23:2117 with SMTP id k5-20020a2e2405000000b002b6df232117mr13970732ljk.43.1689085189634; Tue, 11 Jul 2023 07:19:49 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:ea3d:285e:1d65:c53e:ecb7]) by smtp.gmail.com with ESMTPSA id hb24-20020a170906b89800b00977c7566ccbsm1200329ejb.164.2023.07.11.07.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jul 2023 07:19:49 -0700 (PDT) Message-ID: <25b70e6ec7bef81acac508dc61dfa01e72c96252.camel@cybertec.at> Subject: Re: group by can use alias from select list From: Laurenz Albe To: postgres-hape@gmx.de, pgsql-docs@lists.postgresql.org Date: Tue, 11 Jul 2023 16:19:48 +0200 In-Reply-To: <168871536004.379168.9352636188330923805@wrigleys.postgresql.org> References: <168871536004.379168.9352636188330923805@wrigleys.postgresql.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2023-07-07 at 07:36 +0000, PG Doc comments form wrote: > i have a discussion in pgsql-bugs@lists.postgresql.org=C2=A0about this an= d it is > mentioned in the answers that it is documented and a "feature" of Postgre= s > that this can be done. > If this is wanted the documentation > (https://www.postgresql.org/docs/current/sql-select.html) that mentioned: > [execution order of SELECT that says that GROUP BY is before SELECT] > isn't correct because how=C2=A0 can 4.) be done and the alias from 5.) is= used? > Here is a hint important that there is an exception for alias used in gro= up > by I think that is already documented: > An expression used inside a grouping_element can be an input column name, > or the name or ordinal number of an output column (SELECT list item), > or an arbitrary expression formed from input-column values. An alias in this case would be an output column. Perhaps we can mention the alias explicitly. Yours, Laurenz Albe