From: Mario Splivalo <mario.splivalo@mobart.hr>
To: Mathieu Arnold <mat@mat.cc>
Cc: pgsql-sql@postgresql.org
Subject: Re: ORDER BY CASE ...
Date: Mon, 13 Feb 2006 22:28:38 +0100
Message-ID: <1139866118.1647.2.camel@localhost.localdomain> (raw)
In-Reply-To: <B6687EF0F11B9302F7A56031@[192.168.9.47]>
References: <1139844930.13054.23.camel@localhost.localdomain>
<9693350566E722C466358E08@[192.168.9.47]>
<1139845669.13054.28.camel@localhost.localdomain>
<B6687EF0F11B9302F7A56031@[192.168.9.47]>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mario.splivalo@mobart.hr, mat@mat.cc
Subject: Re: ORDER BY CASE ...
In-Reply-To: <1139866118.1647.2.camel@localhost.localdomain>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox