dbTalk Databases Forums  

[BUGS] strange order by behavior

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] strange order by behavior in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jeffrey Melloy
 
Posts: n/a

Default [BUGS] strange order by behavior - 11-16-2004 , 10:01 PM






I've run across a bug with order by:

select 1 as a order by a;
-- works

select 1 as a, 2 as b order by a;
-- works

select 1 as a, 2 as b order by a + b;
ERROR: column "a" does not exist

select * from (select 1 as a, 2 as b) stuff order by a + b;
-- works

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] strange order by behavior - 11-16-2004 , 11:19 PM






Jeffrey Melloy <jmelloy (AT) visualdistortion (DOT) org> writes:
Quote:
I've run across a bug with order by:
select 1 as a order by a;
-- works

select 1 as a, 2 as b order by a + b;
ERROR: column "a" does not exist
This isn't a bug, strangely enough. The "order by output-column-name"
syntax is a holdover from SQL92, in which ORDER BY items could only be
the names or numbers of SELECT output columns. The new SQL99 theory is
that ORDER BY items are expressions over the input columns, same as the
SELECT output expressions themselves. We have to walk a fine line in
deciding how much of each spec to support, and the line we've drawn is
that simple names will be sought as output column names, but any
expression more complex than a simple name is an expression over the
input columns.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.