Re: ORDER BY CASE ...

Поиск
Список
Период
Сортировка
От Mario Splivalo
Тема Re: ORDER BY CASE ...
Дата
Msg-id 1139866118.1647.2.camel@localhost.localdomain
обсуждение исходный текст
Ответ на Re: ORDER BY CASE ...  (Mathieu Arnold <mat@mat.cc>)
Ответы Re: ORDER BY CASE ...
Список 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 по дате отправления:

Предыдущее
От: Andreas Joseph Krogh
Дата:
Сообщение: Re: Problems with distinct
Следующее
От: Mark Fenbers
Дата:
Сообщение: group by complications