Don Baccus <dhogaza@pacifier.com> writes:
> My first thought is that it is following a simple rule:
> For arithmetic "order by" expressions, either:
> 1. The exact expression must also appear in the "select" list,
> and it must be exact, not just an expression that computes
> the same value as the "order by" expression
> or
> 2. all of the variables used by the expression must be listed
> in the "select" list as simple column names, not as part of
> an expression.
Could be. How about cases like
select distinct x,y+1 from foo order by x+y+1;
> At least, the rule is simple if you can compare expression trees.
I think we have something pretty similar for GROUP BY, actually,
so it may not be hard to make this work.
regards, tom lane