From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Stefan Schwarzer <stefan(dot)schwarzer(at)grid(dot)unep(dot)ch> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: ORDER BY - problem with NULL values |
Date: | 2007-10-10 09:28:05 |
Message-ID: | 470C9B25.8060000@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Stefan Schwarzer wrote:
> Hi there,
>
> if I order a given year in DESCending ORDER, so that the highest values
> (of a given variable) for the countries are displayed at the top of the
> list, then actually the NULL values appear as first. Only below, I find
> the values ordered correctly.
>
> Is there any way to
>
> a) make the countries with NULL values appear at the bottom of the list
> b) neglect the NULL values by still allowing the countries to be
> displayed
Not sure what you mean by (b), but (a) is straightforward enough.
=> SELECT * FROM (SELECT 1 as a UNION SELECT 2 UNION SELECT null::int)
AS foo ORDER BY (a is null), a DESC;
a
---
2
1
(3 rows)
=> SELECT * FROM (SELECT 1 as a UNION SELECT 2 UNION SELECT null::int)
AS foo ORDER BY (a is not null), a DESC;
a
---
2
1
(3 rows)
--
Richard Huxton
Archonet Ltd
From | Date | Subject | |
---|---|---|---|
Next Message | vladimir konrad | 2007-10-10 09:41:05 | Re: corrupt database? |
Previous Message | Richard Huxton | 2007-10-10 09:24:45 | Re: SLEEP in posgresql |