Re: (repost) Help understanding expressions in order by clause - Mailing list pgsql-sql

From Tom Lane
Subject Re: (repost) Help understanding expressions in order by clause
Date
Msg-id 18291.1193331801@sss.pgh.pa.us
Whole thread Raw
In response to (repost) Help understanding expressions in order by clause  (Steve Midgley <public@misuse.org>)
List pgsql-sql
Steve Midgley <public@misuse.org> 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


pgsql-sql by date:

Previous
From: Bricklen Anderson
Date:
Subject: Re: request for help with COPY syntax
Next
From: "Jamie Tufnell"
Date:
Subject: JOINing based on whether an IP address is contained within a CIDR range?