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 1mbl9n-0008P1-4E for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Oct 2021 14:59:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mbl9l-0007Jn-2O for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Oct 2021 14:59:29 +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 1mbl9k-0007JY-1w for pgsql-bugs@lists.postgresql.org; Sat, 16 Oct 2021 14:59:28 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mbl9c-00014e-RU for pgsql-bugs@lists.postgresql.org; Sat, 16 Oct 2021 14:59:26 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 61AC45C00CE; Sat, 16 Oct 2021 10:59:19 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sat, 16 Oct 2021 10:59:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=c1YHXBABKBRjKE4iS4LyMJWWl6TFdvwsbO3rA70uGwY=; b=RN1rgoJF FjuC8yoXST0rq8kgHUxGOhFOTUHET9atmXqnJhsbFWxyi2BO2yaz6L4isW/Z2FwB pKLqeH6ZmG+g8MQ9VygjrQekCC2lWasDPja6mm5DC3JndsWa9Ureh3FRY7r42o+4 UsbKfj1vvBQxXNELZLEnjhSCOPGJ6D3nRdXVL/3NId7BvJr3/QxX/xYiycf0eEHJ I3yyiCH8EXOORLz05Ua3/SCZYBh7hNL7dorLTTx55Bc+FuE28nrpVGK0pekzD829 9tU8SFVvUKhRCCB1l40MITqPa31DcrySGKIVFqoDdVGz7WpJwun96BkPNc6ww+PC O0V5JKVFz3LuBw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvdduiedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtugfgjgesthekre dttddtjeenucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgv segrlhhvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepudejveejffejve duudetvdekieeuiedtvdeileefkeevjedufeeguedvjefhueelnecuffhomhgrihhnpegv nhhtvghrphhrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 16 Oct 2021 10:59:18 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 7B4592A06BC; Sat, 16 Oct 2021 11:59:15 -0300 (-03) Date: Sat, 16 Oct 2021 11:59:15 -0300 From: Alvaro Herrera To: kyle@lahnakoski.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17232: DISTINCT ON does not allow AS Message-ID: <202110161459.hufnhzw4bosn@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <17232-f7e20e9639b6a6c9@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Oct-15, PG Bug reporting form wrote: > The following SQL has an unexpected syntax error > > SELECT DISTINCT ON (col) AS col, col2 FROM test Well, the "ON (col)" part is not an output column -- it's just the specification of the column that you want distinctness over. I suspect you mean SELECT DISTINCT ON (col) col AS col, col2 FROM test ... which looks like a pretty bogus thing to do, since you have no say on *which* values of col2 are you going to get for each distinct value of col. But ... it gives *some* result, at least. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Pensar que el espectro que vemos es ilusorio no lo despoja de espanto, sólo le suma el nuevo terror de la locura" (Perelandra, C.S. Lewis)