Dave Smith <dave(dot)smith(at)candata(dot)com> writes:
> ERROR: For SELECT DISTINCT, ORDER BY expressions must appear in target
> list
> This seems like a bug.
No, it isn't. Consider
SELECT DISTINCT x FROM tab ORDER BY y;
Assuming there are multiple values of y for any given x, how would you
expect the result to be sorted? It's ill-defined.
regards, tom lane