Re: Making NULL entries appear first when ORDER BY <field> ASC

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: "Thomas F(dot)O'Connell" <tfo(at)sitening(dot)com>
Cc: PgSQL - SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Making NULL entries appear first when ORDER BY <field> ASC
Date: 2005-02-23 20:33:22
Message-ID: 20050223203322.GA21904@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Feb 23, 2005 at 13:54:50 -0600,
"Thomas F.O'Connell" <tfo(at)sitening(dot)com> wrote:
> How would one know from the reference material that it is possible to
> include IS NOT NULL in an ORDER BY clause?
>
> Similarly, other than the FAQ, I've never been able to tell from the
> SELECT documentation why ORDER BY random() works.

From the SELECT command documentation:
SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]
* | expression [ AS output_name ] [, ...]
[ FROM from_item [, ...] ]
[ WHERE condition ]
[ GROUP BY expression [, ...] ]
[ HAVING condition [, ...] ]
[ { UNION | INTERSECT | EXCEPT } [ ALL ] select ]
[ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ]
[ LIMIT { count | ALL } ]
[ OFFSET start ]
[ FOR UPDATE [ OF table_name [, ...] ] ]

Notice that for ORDER BY you can supply an expression. That should be a big
clue why you can use IS NOT NULL and random() in an ORDER BY clause.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gregory S. Williamson 2005-02-23 21:10:58 Re: dblink versus schemas. What to use in this case?
Previous Message Thomas F.O'Connell 2005-02-23 20:22:41 Re: Making NULL entries appear first when ORDER BY <field> ASC