Re: CASE in ORDER BY clause

From: Louis-David Mitterrand <vindex+lists-pgsql-general(at)apartia(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: CASE in ORDER BY clause
Date: 2007-07-07 08:37:12
Message-ID: 20070707083712.GA8488@apartia.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

The strange thing is when I try:

select start_date from show_date order by case when start_date > CURRENT_DATE then 'start_date asc' else 'start_date desc ' end;

It lists start_date's without ordering them (does nothing).

However if I try:

select start_date from show_date order by 'start_date desc';

I get a:

ERROR: non-integer constant in ORDER BY

Bug? Inconsistency?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gregory Stark 2007-07-07 09:33:46 Re: CASE in ORDER BY clause
Previous Message Louis-David Mitterrand 2007-07-07 08:29:40 Re: CASE in ORDER BY clause