X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1514C329E72 for ; Sun, 19 Sep 2004 17:18:39 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47654-05 for ; Sun, 19 Sep 2004 16:18:35 +0000 (GMT) Received: from simmts8-srv.bellnexxia.net (simmts8.bellnexxia.net [206.47.199.166]) by svr1.postgresql.org (Postfix) with ESMTP id 578A7329E45 for ; Sun, 19 Sep 2004 17:18:33 +0100 (BST) Received: from localhost ([67.71.24.121]) by simmts8-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20040919161647.TMAF1692.simmts8-srv.bellnexxia.net@localhost>; Sun, 19 Sep 2004 12:16:47 -0400 Received: from [192.168.250.6] ([192.168.250.6]) by (8.11.6/8.11.6) with ESMTP id i8JGIRg15079; Sun, 19 Sep 2004 12:18:31 -0400 Message-ID: <414DB1AB.5080207@sympatico.ca> Date: Sun, 19 Sep 2004 12:19:55 -0400 From: Jean-Luc Lachance User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en, en-us, en-gb, fr, fr-ca MIME-Version: 1.0 To: terry@ashtonwoodshomes.com Cc: mailreg@numerixtechnology.de, pgsql-sql@postgresql.org Subject: Re: ORDER BY and NULLs References: <011d01c49e5b$c88fdb20$2766f30a@development.greatgulfhomes.com> In-Reply-To: <011d01c49e5b$c88fdb20$2766f30a@development.greatgulfhomes.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/130 X-Sequence-Number: 18976 select ... order by "FROM" is not null, "FROM"; If you have large amount of rows (with or without nulls) it is faster if use a partial index. create index ... on ...("FROM"); create index ... on ...("FROM") where "FROM" is null; JLL terry@ashtonwoodshomes.com wrote: > Use the coalesce() function. (coalesce returns the first non-null value in its list) > > Specifically > > ORDER BY coalesce("TO", 0), "FROM" > > If you have records in "TO" column whose values is LESS then 0, then you need to replace 0 with > something that sorts BEFORE the first most value that your TO result can return. > > Terry Fielder > Manager Software Development and Deployment > Great Gulf Homes / Ashton Woods Homes > terry@greatgulfhomes.com > Fax: (416) 441-9085 > > > >>-----Original Message----- >>From: pgsql-sql-owner@postgresql.org >>[mailto:pgsql-sql-owner@postgresql.org]On Behalf Of T E Schmitz >>Sent: Sunday, September 19, 2004 10:58 AM >>To: pgsql-sql@postgresql.org >>Subject: [SQL] ORDER BY and NULLs >> >> >>Hello, >> >>I am using PostgreSQL 7.4.2 and as I understand NULL values >>always sort >>last. >> >>However, I have a table from which select using two numerical >>sort keys >>"FROM" and "TO". "TO" might be NULL and I would like to display those >>rows first (without sorting the column in descending order). >> >>Is there any way this can be achieved without inserting bogus values >>into that column? >> >>-- >> >> >>Regards/Gruß, >> >>Tarlika Elisabeth Schmitz >> >>---------------------------(end of >>broadcast)--------------------------- >>TIP 4: Don't 'kill -9' the postmaster >> > > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html >