pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #18542: Order by expression, that contains column from projection isn't working
2+ messages / 2 participants
[nested] [flat]

* BUG #18542: Order by expression, that contains column from projection isn't working
@ 2024-07-16 09:12 PG Bug reporting form <noreply@postgresql.org>
  2024-07-16 12:45 ` Re: BUG #18542: Order by expression, that contains column from projection isn't working Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2024-07-16 09:12 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: ivningman@gmail.com

The following bug has been logged on the website:

Bug reference:      18542
Logged by:          Aleksandr Novozhilov
Email address:      ivningman@gmail.com
PostgreSQL version: 16.1
Operating system:   Windows
Description:        

select z as y from
 (select 1 as z) x
order by y + 1
That query finishes with error: 
ERROR: column "y" does not exist
  Position: 48
But wrapping it with select works fine:
select * from (select z as y from
 (select 1 as z) x) c
order by y + 1



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #18542: Order by expression, that contains column from projection isn't working
  2024-07-16 09:12 BUG #18542: Order by expression, that contains column from projection isn't working PG Bug reporting form <noreply@postgresql.org>
@ 2024-07-16 12:45 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2024-07-16 12:45 UTC (permalink / raw)
  To: ivningman@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> select z as y from
>  (select 1 as z) x
> order by y + 1
> That query finishes with error: 
> ERROR: column "y" does not exist
>   Position: 48
> But wrapping it with select works fine:
> select * from (select z as y from
>  (select 1 as z) x) c
> order by y + 1

This is not a bug.  See

https://www.postgresql.org/docs/current/queries-order.html

particularly "Note that an output column name has to stand alone, that
is, it cannot be used in an expression".  The fact that we allow this
at all is a hangover from SQL92; per SQL99 and later, variables in
ORDER BY should refer to input columns (that is, outputs of the FROM
clause).

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-07-16 12:45 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-07-16 09:12 BUG #18542: Order by expression, that contains column from projection isn't working PG Bug reporting form <noreply@postgresql.org>
2024-07-16 12:45 ` Tom Lane <tgl@sss.pgh.pa.us>

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