Re: ORDER BY

Поиск
Список
Период
Сортировка
От Alban Hertroys
Тема Re: ORDER BY
Дата
Msg-id 455C2847.5080709@magproductions.nl
обсуждение исходный текст
Ответ на Re: ORDER BY  ("George Pavlov" <gpavlov@mynewplace.com>)
Список pgsql-general
George Pavlov wrote:
>> For larger tables, you may have to resort to a
>> union:
>>
>>    select * from foo where name != 'Other' order by name
>>    union
>>    select * from foo where name = 'Other'
>
> Alas, this suggestion is wrong on two counts: (a) UNION expects a single
> ORDER BY that applies to the whole recordset and which has to come at
> the end; (b) UNION re-sorts anyway (it needs to eliminate the dupes) --

You can also add an imaginary key to sort on, like

select 1, * from foo where name != 'Other'
union all
select 9, * from foo where name = 'Other'
order by 1;

Or independent of column order:

select 1 AS sort_key, * from foo where name != 'Other'
union all
select 9 AS sort_key, * from foo where name = 'Other'
order by sort_key;

Regards,
--
Alban Hertroys
alban@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
   7500 AK Enschede

// Integrate Your World //

В списке pgsql-general по дате отправления:

Предыдущее
От: "SunWuKung"
Дата:
Сообщение: calculated default
Следующее
От: "Albe Laurenz"
Дата:
Сообщение: Re: dependency on 32 bit libpq.so on 64 bit Postgres server.