Re: CASE in ORDER BY clause

Поиск
Список
Период
Сортировка
От Perry Smith
Тема Re: CASE in ORDER BY clause
Дата
Msg-id 94BEBE52-8D5D-48D5-AF58-7FC579A4DDC3@easesoftware.com
обсуждение исходный текст
Ответ на Re: CASE in ORDER BY clause  (Gregory Stark <stark@enterprisedb.com>)
Ответы Re: CASE in ORDER BY clause  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: CASE in ORDER BY clause  (Martijn van Oosterhout <kleptog@svana.org>)
Список pgsql-general
> On Fri, Jul 06, 2007 at 08:02:54PM +0400, Viatcheslav Kalinin wrote:
>>
>> # select start_date from show_date
>> # order by
>> # case when start_date > CURRENT_DATE then start_date end desc,
>> # case when start_date <= CURRENT_DATE then start_date end asc;
>>
I am very novice, but that looks odd to me.  I would have expected
the asc or desc keywords need to go inside the case (before the
end).  Otherwise you have either:

... order by start_date desc, asc;

or

... order by desc, start_date asc;

This is what I would expect the syntax to be:

# select start_date from show_date
# order by
# case when start_date > CURRENT_DATE then start_date desc end,
# case when start_date <= CURRENT_DATE then start_date asc end;

Or, it seems like you could do:

# select start_date from show_date
# order by start_date
# case when start_date > CURRENT_DATE then desc end,
# case when start_date <= CURRENT_DATE then asc end;


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

Предыдущее
От: Gregory Stark
Дата:
Сообщение: Re: CASE in ORDER BY clause
Следующее
От: Carmen Martinez
Дата:
Сообщение: catalog location