order by alias - doesn't work sometimes?

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: order by alias - doesn't work sometimes?
Date: 2025-10-14 14:50:56
Message-ID: aO5jUGlQgBBAOp4_@depesz.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,
It very well might not be a bug, but it caught me by surprise.

Tested on Pg 19 from git head:

=$ select unnest( ARRAY['d', 'c', 'a'] ) x order by x;
x
───
a
c
d
(3 rows)

Works, and shows that I can order by alias name of column that is generated by srf.

But:

=$ select unnest( ARRAY['d', 'c', 'a'] ) x order by x <> 'a';
ERROR: column "x" does not exist
LINE 1: select unnest( ARRAY['d', 'c', 'a'] ) x order by x <> 'a';
^

Obviously I can put the unnest() call in from, and then it works, but
I'm curious, why we can `order by x`, but not `order by x <> 'a'` ?

Best regards,

depesz

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-10-14 15:10:31 Re: order by alias - doesn't work sometimes?
Previous Message Heikki Linnakangas 2025-10-14 11:39:26 Re: BUG #19080: CancelRequest message documentation bug