Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 7B5A39F98FB for ; Thu, 25 Oct 2007 14:03:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 91124-05-5 for ; Thu, 25 Oct 2007 14:03:30 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 518CB9F9258 for ; Thu, 25 Oct 2007 14:03:33 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l9PH3LMO018292; Thu, 25 Oct 2007 13:03:21 -0400 (EDT) To: Steve Midgley cc: pgsql-sql@postgresql.org Subject: Re: (repost) Help understanding expressions in order by clause In-reply-to: <20071025164917.D310A9F9251@postgresql.org> References: <20071024172620.4ECD2607787@mx1.hub.org> <20071025164917.D310A9F9251@postgresql.org> Comments: In-reply-to Steve Midgley message dated "Thu, 25 Oct 2007 09:44:36 -0700" Date: Thu, 25 Oct 2007 13:03:21 -0400 Message-ID: <18291.1193331801@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/121 X-Sequence-Number: 29493 Steve Midgley writes: > select * from test_order > order by id <> 3, email > --sql end > Putting the expression "id <> 3" causes the id of 3 to sort to the TOP > of the list. This statement does the same thing: > select * from test_order > order by id = 3 DESC, email > I know there is a good, rational reason for this, and I'm hoping > someone will explain it to me? These expressions yield boolean true or false, and false sorts before true. regards, tom lane