Re: How do I change sort order behavious with nulls - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: How do I change sort order behavious with nulls
Date
Msg-id 20050219180107.GB15226@wolff.to
Whole thread Raw
In response to How do I change sort order behavious with nulls  (charlie clark <charlie@begeistert.org>)
Responses Re: How do I change sort order behavious with nulls
List pgsql-general
On Sat, Feb 19, 2005 at 18:04:32 +0100,
  charlie clark <charlie@begeistert.org> wrote:
> Dear list,
>
> is there a simple way to change the way ORDER BY works on columns with
> NULLs? I can understand the need for default behaviour but there must be
> cases when this is undesirable. I have such a query with the NULLs arising
> as the result of an OUTER JOIN and I would like to ORDER BY DESC with
> NULLs treated as <= 0. I've already tried a few things but nothing's
> working so far.

Presumably what you mean is that you want NULLs to be output last when
doing a descending order by.

You can do this using ORDER BY whatever IS NULL ASC, whatever DESC .

If you really mean you want to treat them as less than or equal to
0, then you can pick such a value and use coalesce to change NULLs
to that value in the ORDER BY clause.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: How do I change sort order behavious with nulls
Next
From: Frank Finner
Date:
Subject: Re: Client lib v. 7.3 to access 8.0 db server. Compatible