Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 7EFED2E010F for ; Wed, 30 Jan 2008 16:24:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 21333-02-8 for ; Wed, 30 Jan 2008 16:24:18 -0400 (AST) Received: from oxford.xeocode.com (unknown [87.127.95.196]) by postgresql.org (Postfix) with ESMTP id B02C22E0125 for ; Wed, 30 Jan 2008 16:24:21 -0400 (AST) Received: from localhost ([127.0.0.1] helo=oxford.xeocode.com) by oxford.xeocode.com with esmtp (Exim 4.69) (envelope-from ) id 1JKJTd-0001JJ-EJ; Wed, 30 Jan 2008 20:24:09 +0000 To: "Tom Lane" Cc: "A. Kretschmer" , Subject: Re: Sql ORDER BY and ASC/DESC question In-Reply-To: <14687.1201716029@sss.pgh.pa.us> (Tom Lane's message of "Wed\, 30 Jan 2008 13\:00\:29 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) X-Draft-From: ("nnimap+mail01.enterprisedb.com:INBOX" 61483) References: <20080130104226.GF26490@a-kretschmer.de> <87tzkvbfr6.fsf@oxford.xeocode.com> <14687.1201716029@sss.pgh.pa.us> From: Gregory Stark Organization: EnterpriseDB Date: Wed, 30 Jan 2008 20:24:09 +0000 Message-ID: <87ir1buknq.fsf@oxford.xeocode.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/231 X-Sequence-Number: 30084 "Tom Lane" writes: > Gregory Stark writes: > >> ORDER BY >> CASE ? >> WHEN 1 THEN name ASC > > Uh, no, putting the ASC/DESC decoration inside a CASE like that is not > gonna work doh! I had a feeling something was wrong but couldn't put my finger on it before I hit send. Sigh. > For numerical sort keys you can cheat by using "-x" in place of > "x DESC", but I'm not aware of any equivalent hack for text keys. Yeah, you could do a really kludgy thing with a second sort expression where you null out one expression or the other depending on the parameter but it starts to look more and more spaghetti-like. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!