| From: | Louis-David Mitterrand <vindex+lists-pgsql-general(at)apartia(dot)org> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | CASE in ORDER BY clause |
| Date: | 2007-07-06 15:09:04 |
| Message-ID: | 20070706150904.GA19593@apartia.fr |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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_date asc 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 asc end;
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,
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David Fetter | 2007-07-06 15:36:29 | Re: Polymorphic delete help needed |
| Previous Message | Sibte Abbas | 2007-07-06 15:04:46 | Re: DB crashed and duplicated template0 db |