From: Ragnar Hafstaư <gnari@simnet.is>
To: Andreas Joseph Krogh <andreak@officenet.no>
Cc: pgsql-sql@postgresql.org
Subject: Re: Making NULL entries appear first when ORDER BY <field>
Date: Wed, 16 Feb 2005 02:31:13 +0000
Message-ID: <1108521073.28180.5.camel@localhost.localdomain> (raw)
In-Reply-To: <200502160055.59288.andreak@officenet.no>
References: <200502160055.59288.andreak@officenet.no>
On Wed, 2005-02-16 at 00:55 +0000, Andreas Joseph Krogh wrote:
> SELECT start_date, start_time, end_time, title
> FROM onp_crm_activity_log
> WHERE start_date IS NOT NULL
> ORDER BY start_date ASC, start_time ASC;
>
> start_date | start_time | end_time | title
> ---------------------+---------------------+---------------------+-----------
> 2005-02-03 00:00:00 | 2005-02-03 08:00:00 | | Something
> 2005-02-03 00:00:00 | 2005-02-03 09:00:00 | 2005-02-03 12:00:00 | Something
> 2005-02-03 00:00:00 | | | Something
>
>
> Now, as you see, touples with NULL in the "start_time"-field appear "after"
> the others. I would like to make all entries where start_time IS NULL apear
> *before* all the others. Any idea how to achieve this?
how about ORDER BY start_date ,
COALESCE(start_time,'0001-01-01 00:00:00'::timestamp)
?
gnari
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gnari@simnet.is, andreak@officenet.no
Subject: Re: Making NULL entries appear first when ORDER BY <field>
In-Reply-To: <1108521073.28180.5.camel@localhost.localdomain>
* 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