Re: ORDER BY CASE ... - Mailing list pgsql-sql

From Mario Splivalo
Subject Re: ORDER BY CASE ...
Date
Msg-id 1139866118.1647.2.camel@localhost.localdomain
Whole thread Raw
In response to Re: ORDER BY CASE ...  (Mathieu Arnold <mat@mat.cc>)
Responses Re: ORDER BY CASE ...  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-sql
On Mon, 2006-02-13 at 17:10 +0100, Mathieu Arnold wrote:
> | It works like this:
> | 
> | ORDER BY (CASE WHEN 5=5 THEN "from"::varchar ELSE
> | receiving_time::varchar) DESC.
> | 
> | Is there a way to have DESC/ASC inside of a CASE?
> | 
> |     Mario
> 
> No, you don't understand, you should do something like :
> 
> case when foo = bar then from else receiving_time desc end
> 

Can't do so, because receiving_time is timestamptz, and "from" is
varchar. There:

pulitzer2=# select id, "from", receiving_time from messages order by
case when 2=3 then "from" else receiving_time end desc limit 5;
ERROR:  CASE types timestamp with time zone and character varying cannot
be matched

I need to explicitly cast receiving_time into varchar.

What I would like to include ASC/DESC into CASE, but I guess that's not
possible.
Mike



pgsql-sql by date:

Previous
From: Andreas Joseph Krogh
Date:
Subject: Re: Problems with distinct
Next
From: Mark Fenbers
Date:
Subject: group by complications