Only specifying a default value does not prevent a NULL from being entered either through accident or ignorance:

jan28-05=# create table test (foo text, foo1 int4 default(0));
CREATE TABLE
jan28-05=# insert into test values('a',1);
INSERT 98685 1
jan28-05=# insert into test values('b',4);
INSERT 98686 1
jan28-05=# insert into test values('c',NULL);
INSERT 98687 1
jan28-05=# insert into test values('d');
INSERT 98688 1
jan28-05=# select * from test;
foo | foo1
-----+------
a   |    1
b   |    4
c   |
d   |    0
(4 rows)

George

----- Original Message ----- From: "Kenneth Gonsalves" <[EMAIL PROTECTED]>
To: "Richard Huxton" <dev@archonet.com>
Cc: <[EMAIL PROTECTED]>; <pgsql-sql@postgresql.org>
Sent: Thursday, March 17, 2005 11:19 PM
Subject: Re: [SQL] Query performance problem



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?

--
regards
kg

http://www.livejournal.com/users/lawgon
tally ho! http://avsap.sourceforge.net
àààààààààà ààààà!

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
   (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])



---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Reply via email to