Search Postgresql Archives

Re: CASE in ORDER BY clause

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jul 07, 2007 at 01:49:09PM -0500, Perry Smith 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:

The keyword asc/desc applies to an expression, the result is not an
expression, hence you cannot put the asc/desc inside a case.

> ... order by start_date desc, asc;
> or
> ... order by desc, start_date asc;

Almost, it's actually:
 ... order by start_date desc, null asc;
 or
 ... order by null desc, start_date asc;

Ordering by a constant has no effect, which is why it works.

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog@xxxxxxxxx>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux