Skip site navigation (1) Skip section navigation (2)

Re: (repost) Help understanding expressions in order by clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Steve Midgley <public(at)misuse(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: (repost) Help understanding expressions in order by clause
Date: 2007-10-25 17:03:21
Message-ID: 18291.1193331801@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-sql
Steve Midgley <public(at)misuse(dot)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

In response to

pgsql-sql by date

Next:From: Jamie TufnellDate: 2007-10-25 18:22:41
Subject: JOINing based on whether an IP address is contained within a CIDR range?
Previous:From: Bricklen AndersonDate: 2007-10-25 16:57:49
Subject: Re: request for help with COPY syntax

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group