Re: Sql ORDER BY and ASC/DESC question

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Sql ORDER BY and ASC/DESC question
Дата
Msg-id 14687.1201716029@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Sql ORDER BY and ASC/DESC question  (Gregory Stark <stark@enterprisedb.com>)
Ответы Re: Sql ORDER BY and ASC/DESC question  (Gregory Stark <stark@enterprisedb.com>)
Список pgsql-sql
Gregory Stark <stark@enterprisedb.com> writes:
> If you're not concerned with the planner being able to find indexes to satisfy
> these orderings (ie, you don't mind always doing a sort) you could do
> something like:

> ORDER BY 
>  CASE ? 
>  WHEN 1 THEN name ASC
>  WHEN 2 THEN name DESC
>  WHEN 3 THEN height ASC
>  WHEN 4 THEN height DESC
>  ELSE id ASC
>  END

Uh, no, putting the ASC/DESC decoration inside a CASE like that is not
gonna work --- it's only allowed at the top level of an ORDER BY clause.
For numerical sort keys you can cheat by using "-x" in place of
"x DESC", but I'm not aware of any equivalent hack for text keys.
        regards, tom lane


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

Предыдущее
От: Gregory Stark
Дата:
Сообщение: Re: Sql ORDER BY and ASC/DESC question
Следующее
От: Gregory Stark
Дата:
Сообщение: Re: Sql ORDER BY and ASC/DESC question