Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E55E7476860 for ; Fri, 27 Sep 2002 12:16:23 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 22C5E476CA3 for ; Fri, 27 Sep 2002 12:15:59 -0400 (EDT) Received: from [63.195.55.98] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.5.9) with HTTP id 1731902; Fri, 27 Sep 2002 09:16:08 -0700 From: "Josh Berkus" Subject: Re: Null not equal to '' (empty) To: Ajit Aranha , pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.5.9 Date: Fri, 27 Sep 2002 09:16:08 -0700 Message-ID: In-Reply-To: <20020920060916.42881.qmail@web14104.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200209/383 X-Sequence-Number: 9660 Ajit, > Why is ''(empty) not equal to null? Its a major headache when > porting > from other RDBMS like Oracle. '' is not equal to NULL because that is the ANSI SQL92 and SQL99 international specification. The fact that other databases fail to follow the specification (and '' = NULL is *not* standard Oracle 8 behavior, either, so I don't know what you are porting from ... MS Access?) is not our concern. NULL is not equal to *anything*, including itself. Nor is it greater or less than anything. In fact, any operation involving NULL should result in NULL. This is the SQL spec, becuase NULL represents "unknown" and thus cannot be evaluated. For my intranet applications, I wrote a set of functions called "is_empty(data)" since my web programmer is rather liberal in substituting NULL for '' or for '0' or whatever. They go like this: CREATE FUNCTION is_empty( VARCHAR ) RETURNS BOOLEAN AS ' SELECT $1 IS NULL OR BTRIM($1) = ''; ' LANGUAGE 'sql' WITH (ISCACHABLE); CREATE FUNCTION is_empty( NUMERIC ) RETURNS BOOLEAN AS ' SELECT $1 IS NULL OR $1 = 0::NUMERIC; ' LANGUAGE 'sql' WITH (ISCACHABLE); etc. This will give you an all-purpose "empty value" detector. -Josh Berkus Aglio Database Solutions San Francisco