pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hubert depesz lubaczewski <depesz@depesz.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: order by alias - doesn't work sometimes?
Date: Tue, 14 Oct 2025 17:46:23 +0200
Message-ID: <aO5wT-h2C5WACgaq@depesz.com> (raw)
In-Reply-To: <959907.1760454631@sss.pgh.pa.us>
References: <aO5jUGlQgBBAOp4_@depesz.com>
	<959907.1760454631@sss.pgh.pa.us>

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






view thread (3+ messages)

Message-ID: <aO5wT-h2C5WACgaq@depesz.com>
Permalink:  ../aO5wT-h2C5WACgaq@depesz.com/
Also on:    postgresql.org/message-id/aO5wT-h2C5WACgaq@depesz.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: depesz@depesz.com, tgl@sss.pgh.pa.us, pgsql-bugs@lists.postgresql.org
  Subject: Re: order by alias - doesn't work sometimes?
  In-Reply-To: <aO5wT-h2C5WACgaq@depesz.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox