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 036F19DC99F for ; Mon, 13 Feb 2006 12:01:33 -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 47199-05 for ; Mon, 13 Feb 2006 12:01:30 -0400 (AST) X-Greylist: delayed 00:21:03.443784 by SQLgrey- Received: from spoetnik.xs4all.nl (spoetnik.xs4all.nl [213.84.24.58]) by postgresql.org (Postfix) with ESMTP id 9F6709DC952 for ; Mon, 13 Feb 2006 12:01:30 -0400 (AST) Received: by spoetnik.xs4all.nl (Postfix, from userid 1000) id 57EDD1CC64; Mon, 13 Feb 2006 16:40:24 +0100 (CET) Date: Mon, 13 Feb 2006 16:40:24 +0100 From: Reinoud van Leeuwen To: pgsql-sql@postgresql.org Subject: Re: ORDER BY CASE ... Message-ID: <20060213154024.GJ46853@spoetnik.xs4all.nl> Mail-Followup-To: pgsql-sql@postgresql.org References: <1139844930.13054.23.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1139844930.13054.23.camel@localhost.localdomain> User-Agent: Mutt/1.4.2.1i X-message-flag: Warning! The sender of this mail thinks you should use a more secure email client. X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200602/134 X-Sequence-Number: 24144 On Mon, Feb 13, 2006 at 04:35:30PM +0100, Mario Splivalo wrote: > 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; I'm not sure what you are trying to do here, but it seems that an order by statement should at least contain something that is part of the resultrow. "case when 5=5 then 2 else 3 end desc limit 5" does not contain any column to sort on. So I think it will evaluate to some constant value and not sorting is really done -- __________________________________________________ "Nothing is as subjective as reality" Reinoud van Leeuwen reinoud.v@n.leeuwen.net http://www.xs4all.nl/~reinoud __________________________________________________