order by alias - doesn't work sometimes?
hubert depesz lubaczewski <depesz@depesz.com>
From: hubert depesz lubaczewski <depesz@depesz.com>
To: pgsql-bugs@lists.postgresql.org
Date: 2025-10-14T14:50:56Z
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