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 2E09556A4F for ; Fri, 18 Mar 2005 13:19:28 +0000 (GMT) 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 30292-04 for ; Fri, 18 Mar 2005 13:19:25 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 651FF56A41 for ; Fri, 18 Mar 2005 13:19:24 +0000 (GMT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 360AB3594F; Fri, 18 Mar 2005 05:19:28 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 3477B35932; Fri, 18 Mar 2005 05:19:28 -0800 (PST) Date: Fri, 18 Mar 2005 05:19:28 -0800 (PST) From: Stephan Szabo To: Kenneth Gonsalves Cc: Richard Huxton , weberp@paradise.net.nz, pgsql-sql@postgresql.org Subject: Re: Query performance problem In-Reply-To: <200503181049.47566.lawgon@thenilgiris.com> Message-ID: <20050318051614.Q61964@megazone.bigpanda.com> References: <200503172120.20676.weberp@paradise.net.nz> <200503171801.19412.lawgon@thenilgiris.com> <42398EB9.2050707@archonet.com> <200503181049.47566.lawgon@thenilgiris.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/258 X-Sequence-Number: 20737 On Fri, 18 Mar 2005, Kenneth Gonsalves wrote: > On Thursday 17 Mar 2005 7:35 pm, Richard Huxton wrote: > > > Not necessarily. NOT NULL here helps to ensure you can add values > > together without the risk of a null result. There are plenty of > > "amount" columns that should be not-null (total spent, total > > ordered etc). > > that makes sense - but is it necessary to have a not null constraint > when there is a default value? It's also an added check which prevents you from explicitly setting the value to NULL in an insert or update, since "insert into foo(col1) values (NULL);" shouldn't insert the default value into col1. This is relatively minor generally, but if you have queries whose behavior is broken by NULLs (things using IN/NOT IN for example) it's better to be safe.