Am I misusing the ORDER BY with CASE, or, what? :)

I have a table, messages, half dozen of columns, exposing here just
three of them:

pulitzer2=# select id, "from", receiving_time from messages where
service_id = 20 order by case when 5=5 then 2 else 3 end desc limit 5;
   id   |     from      |     receiving_time
--------+---------------+------------------------
 869585 | +385989095824 | 2005-12-08 16:04:23+01
 816579 | +385915912312 | 2005-11-23 17:51:06+01
 816595 | +38598539263  | 2005-11-23 17:58:21+01
 816594 | +385915929232 | 2005-11-23 17:57:30+01
 816589 | +385912538567 | 2005-11-23 17:54:32+01
(5 rows)


pulitzer2=# select id, "from", receiving_time from messages where
service_id = 20 order by case when 5=6 then 2 else 3 end desc limit 5;
   id   |     from      |     receiving_time
--------+---------------+------------------------
 869585 | +385989095824 | 2005-12-08 16:04:23+01
 816579 | +385915912312 | 2005-11-23 17:51:06+01
 816595 | +38598539263  | 2005-11-23 17:58:21+01
 816594 | +385915929232 | 2005-11-23 17:57:30+01
 816589 | +385912538567 | 2005-11-23 17:54:32+01
(5 rows)


I tought I'd get differently sorted data, since in the first query I
said 5=5, and in second I said 5=6. 

Is this a right way to use CASE on ORDER BY, or? I need to sord the data
in the function depending on the function parametar. If it's true,
randomize the sort, if not, sort by receiving_time, newest first.

So, can I do it with ORDER BY CASE ... END, or do I need to have two
querries, and then first check for the value of the parametar, and then,
according to that value, call the SELECTs wich sort randomly, or by
receiving_time.

        Mario

P.S. The postgres is 8.1.2. 
-- 
Mario Splivalo
Mob-Art
[EMAIL PROTECTED]

"I can do it quick, I can do it cheap, I can do it well. Pick any two."



---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to [EMAIL PROTECTED] so that your
       message can get through to the mailing list cleanly

Reply via email to