pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mathieu Arnold <mat@mat.cc>
To: mario.splivalo@mobart.hr
Cc: pgsql-sql@postgresql.org
Subject: Re: ORDER BY CASE ...
Date: Mon, 13 Feb 2006 17:10:48 +0100
Message-ID: <B6687EF0F11B9302F7A56031@[192.168.9.47]> (raw)
In-Reply-To: <1139845669.13054.28.camel@localhost.localdomain>
References: <1139844930.13054.23.camel@localhost.localdomain>
	<9693350566E722C466358E08@[192.168.9.47]>
	<1139845669.13054.28.camel@localhost.localdomain>

+-le 13/02/2006 16:47 +0100, Mario Splivalo a dit :
| On Mon, 2006-02-13 at 16:39 +0100, Mathieu Arnold wrote:
|> | 
|> | I tought I'd get differently sorted data, since in the first query I
|> | said 5=5, and in second I said 5=6. 
|> 
|> Well, no, in the first, the result of the CASE is 2, and in the second 3,
|> it means that for every line, it'll sort using "2" as value for the first,
|> and "3" for the second query.
|> 
| 
| Yes, I realized just a second ago that when ORDER BY is CASED, numbers
| aren't the column numbers, but the integers itself.
| 
| 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

-- 
Mathieu Arnold



view thread (7+ messages)  latest in thread

Message-ID: <B6687EF0F11B9302F7A56031@[192.168.9.47]>
Permalink:  ../B6687EF0F11B9302F7A56031@%5B192.168.9.47%5D/
Also on:    postgresql.org/message-id/B6687EF0F11B9302F7A56031@[192.168.9.47]

 · 

reply

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: mat@mat.cc, mario.splivalo@mobart.hr
  Subject: Re: ORDER BY CASE ...
  In-Reply-To: <B6687EF0F11B9302F7A56031@[192.168.9.47]>

* 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