Re: Problem of Null Ordering - Mailing list pgsql-general

From SZUCS Gábor
Subject Re: Problem of Null Ordering
Date
Msg-id 003c01c29ab8$45fe5130$0a03a8c0@fejleszt2
Whole thread Raw
In response to Problem of Null Ordering  (Harry Yau <harry.yau@regaltronic.com>)
List pgsql-general
I often use this trick:

SELECT * FROM t1 ORDER BY (IF1 IS NOT NULL), if1;

The first order is by a boolean value, and false comes first. Effectively,
it's the same thought as the union. But if you fear boolean expressions, try
this:

SELECT * FROM t1 ORDER BY (CASE WHEN if1 IS NULL THEN 0 ELSE 1 END), if1;

HTH,

G.
--
while (!asleep()) sheep++;

---------------------------- cut here ------------------------------
----- Original Message -----
From: "Harry Yau" <harry.yau@regaltronic.com>
Sent: Tuesday, December 03, 2002 10:54 AM


> I know that it is possible to do this query. Such as
> SELECT *, 0 AS PreOrder FROM T1 WHERE IF1 IS NULL
> UNION ALL
> SELECT *, 1 AS PreOrder FROM T1 WHERE IF1 IS NOT NULL
> ORDER BY PreOrder, IF1



pgsql-general by date:

Previous
From: Lee Kindness
Date:
Subject: 7.3 -> pg_atoi: zero-length string
Next
From: "Ben-Nes Michael"
Date:
Subject: Re: 7.3 -> pg_atoi: zero-length string