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 1v8hEL-001ghc-2g for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Oct 2025 15:46:28 +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 1v8hEJ-0019jy-LZ for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Oct 2025 15:46:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v8hEJ-0019jp-D5 for pgsql-bugs@lists.postgresql.org; Tue, 14 Oct 2025 15:46:26 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v8hEG-001jqM-34 for pgsql-bugs@lists.postgresql.org; Tue, 14 Oct 2025 15:46:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description; bh=Jf27k7FzEukb6uZ5l0wCF9qIGUpzTwjgIJp/6J2fSYM=; b=s85JHy/60DVbcKqZvWCmbviAW9 YHssgmxKN/DKzytASQti8G/CFfarvOcyEeOaaELeUM6yPGj5b1H4sZMRUearyGrRObrpx7hUuErDi 6RQSmjUFbUbqhQwgmKVWnXj8kOisKH4mbRvRp+hGWZ5trtTmuiC+TFigiCdi5oLjwyGY=; Received: from depesz by depesz.com with local (Exim 4.96) (envelope-from ) id 1v8hEF-00FHTd-0J; Tue, 14 Oct 2025 17:46:23 +0200 Date: Tue, 14 Oct 2025 17:46:23 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org Subject: Re: order by alias - doesn't work sometimes? Message-ID: Reply-To: depesz@depesz.com References: <959907.1760454631@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <959907.1760454631@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Oct 14, 2025 at 11:10:31AM -0400, Tom Lane wrote: > ORDER BY output-column-alias is a messy hangover from SQL92. > In later SQL versions, identifiers in ORDER BY have the same > interpretation as in WHERE and other clauses, namely they are > columns sourced by the FROM clause. Supporting both interpretations > makes for a lot of ambiguity, so we only allow the old interpretation > in exactly the case required by SQL92, namely "ORDER BY identifier". > > This is documented ... Well, now I understand this: >> Each expression can be the name or ordinal number of an output column >> (SELECT list item), or it can be an arbitrary expression formed from >> input-column values. better. Thanks. Best regards, depesz