CASE in ORDER BY clause - Mailing list pgsql-general

From Louis-David Mitterrand
Subject CASE in ORDER BY clause
Date
Msg-id 20070706150904.GA19593@apartia.fr
Whole thread Raw
Responses Re: CASE in ORDER BY clause  (Viatcheslav Kalinin <vka@ipcb.net>)
Re: CASE in ORDER BY clause  (Viatcheslav Kalinin <vka@ipcb.net>)
List pgsql-general
Hi,

I am trying the following:

    critik=# select start_date from show_date order by case when start_date > CURRENT_DATE then start_date desc else
start_dateasc end; 
    ERROR:  syntax error at or near "desc"
    LINE 1: ...se when start_date > CURRENT_DATE then start_date desc else
    ...

If I remove the "desc" and "asc" then the quey is accepted but doesn't
do what I want.

OTOH if I try:

    critik=# select start_date from show_date order by start_date case when start_date > CURRENT_DATE then desc else
ascend; 
    ERROR:  syntax error at or near "case"
    LINE 1: ...ect start_date from show_date order by start_date case when ...

How can i order ASC or DESC depending on a condition?

Thanks,

pgsql-general by date:

Previous
From: "Sibte Abbas"
Date:
Subject: Re: DB crashed and duplicated template0 db
Next
From: David Fetter
Date:
Subject: Re: Polymorphic delete help needed