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 37FFF3A4498 for ; Tue, 26 Oct 2004 22:01:50 +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 41882-02 for ; Tue, 26 Oct 2004 21:01:46 +0000 (GMT) Received: from nordine.ateur (main.librelogiciel.com [62.212.108.58]) by svr1.postgresql.org (Postfix) with ESMTP id 625563A44BE for ; Tue, 26 Oct 2004 22:01:47 +0100 (BST) Received: from [192.168.1.2] (helo=localhost.localdomain ident=Debian-exim) by nordine.ateur with esmtp (Exim 3.36 #1 (Debian)) id 1CMYRd-0005tT-00; Tue, 26 Oct 2004 23:01:29 +0200 Received: from jerome by localhost.localdomain with local (Exim 4.34) id 1CMYRd-0001Zm-CY; Tue, 26 Oct 2004 23:01:29 +0200 Date: Tue, 26 Oct 2004 23:01:29 +0200 To: Stephan Szabo Cc: pgsql-sql@postgresql.org Subject: Re: How do you compare (NULL) and (non-NULL)? Message-ID: <20041026210129.GC5922@localhost.localdomain> References: <417EB238.1000109@kencast.com> <20041026134508.N5021@megazone.bigpanda.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041026134508.N5021@megazone.bigpanda.com> User-Agent: Mutt/1.5.6+20040907i From: Jerome Alet 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: 200410/190 X-Sequence-Number: 19293 On Tue, Oct 26, 2004 at 01:48:48PM -0700, Stephan Szabo wrote: > On Tue, 26 Oct 2004, Wei Weng wrote: > > > In the following query > > > > SELECT Parent FROM Channels ORDER BY Parent ASC; > > > > If I have a couple of (NULL)s in the field [Parent], they will be listed at > > the bottom of the query result. > > > > Is it because PostgreSQL considers (NULL) as the biggest value? If I run the > > same query under MSSQL Server 2000, I get the exact opposite result > > regarding the order of (NULL)s and (non-NULL) values. They are listed at the > > very beginning of the query result. you could try to use COALESCE to treat NULLs as either a minimal or maximal value so that your ordering is correct : SELECT Parent FROM Channels ORDER BY COALESCE(Parent, -1) ASC; to treat NULLs as -1 for example hth Jerome Alet