X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3418F9DCC0C for ; Mon, 13 Feb 2006 12:10:55 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46173-08 for ; Mon, 13 Feb 2006 12:10:51 -0400 (AST) X-Greylist: delayed 00:31:28.392195 by SQLgrey- Received: from plouf.absolight.net (plouf.absolight.net [193.30.224.136]) by postgresql.org (Postfix) with ESMTP id 784629DCC2A for ; Mon, 13 Feb 2006 12:10:51 -0400 (AST) Received: from andromede.in.absolight.net (andromede.in.absolight.net [193.30.224.82]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by plouf.absolight.net (Postfix) with ESMTP id 2531F4A9C28; Mon, 13 Feb 2006 17:10:50 +0100 (CET) Date: Mon, 13 Feb 2006 17:10:48 +0100 From: Mathieu Arnold To: mario.splivalo@mobart.hr cc: pgsql-sql@postgresql.org Subject: Re: ORDER BY CASE ... Message-ID: 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> X-Mailer: Mulberry/4.0.4 (Win32) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.06 required=5 tests=[AWL=0.060] X-Spam-Score: 0.06 X-Spam-Level: X-Archive-Number: 200602/135 X-Sequence-Number: 24145 +-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