From: SZUCS Gábor <surrano@mailbox.hu>
To: pgsql-general@postgresql.org
Subject: Re: Problem of Null Ordering
Date: Tue, 3 Dec 2002 11:39:33 +0100
Message-ID: <003c01c29ab8$45fe5130$0a03a8c0@fejleszt2> (raw)
References: <3DEC75A5.D544E5D@regaltronic.com>
<3DEC785E.9010604@mega-bucks.co.jp>
<3DEC7F45.65064CE7@regaltronic.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: surrano@mailbox.hu, pgsql-general@postgresql.org
Subject: Re: Problem of Null Ordering
In-Reply-To: <003c01c29ab8$45fe5130$0a03a8c0@fejleszt2>
References: <3DEC75A5.D544E5D@regaltronic.com> <3DEC785E.9010604@mega-bucks.co.jp> <3DEC7F45.65064CE7@regaltronic.com> <003c01c29ab8$45fe5130$0a03a8c0@fejleszt2>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox