Re: [SQL] Question about SELECT and ORDER BY - Mailing list pgsql-sql

From Tom Lane
Subject Re: [SQL] Question about SELECT and ORDER BY
Date
Msg-id 28465.949599989@sss.pgh.pa.us
Whole thread Raw
In response to Question about SELECT and ORDER BY  ("Vladimir Terziev" <vlady@school.digsys.bg>)
List pgsql-sql
"Vladimir Terziev" <vlady@school.digsys.bg> writes:
> I have a query:
>    SELECT table1.attr1 AS ALIAS, attr2 from table1 UNION ALL
>    SELECT table2.attr1, attr3 from table2 ORDER BY ALIAS;

> I want to have a result from ORDER BY length(ALIAS), but this is imposible.

SELECT ... UNION ... ORDER BY is pretty broken in current sources;
in particular adding a hidden column to sort on doesn't work when
there's a UNION.  I've looked a little bit at fixing this, and it
looks like it will take the long-threatened querytree restructuring
to deal with it in any sensible fashion.  Maybe that'll happen for 7.1.

In the meantime use Mark Volpe's workaround of only sorting on
columns that are in the select list.
        regards, tom lane


pgsql-sql by date:

Previous
From: "David Warren"
Date:
Subject: sql statements
Next
From: Tom Lane
Date:
Subject: Re: [SQL] sql statements