X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 48EC7475BF9 for ; Wed, 12 Feb 2003 15:27:48 -0500 (EST) Received: from wolff.to (wolff.to [66.93.249.74]) by postgresql.org (Postfix) with SMTP id 391CC475C14 for ; Wed, 12 Feb 2003 15:27:47 -0500 (EST) Received: (qmail 30583 invoked by uid 500); 12 Feb 2003 20:41:09 -0000 Date: Wed, 12 Feb 2003 14:41:09 -0600 From: Bruno Wolff III To: Arunachalam Jaisankar Cc: pgsql-sql@postgresql.org Subject: Re: null foreign key column Message-ID: <20030212204109.GB30483@wolff.to> Mail-Followup-To: Arunachalam Jaisankar , pgsql-sql@postgresql.org References: <000801c2d181$6c0be360$020000c0@singlarc01> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000801c2d181$6c0be360$020000c0@singlarc01> User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/259 X-Sequence-Number: 11657 On Tue, Feb 11, 2003 at 16:55:28 +1300, Arunachalam Jaisankar wrote: > Hi all, > > I would like to have a foreign key column in my table which allows null value also. > But the below create table sql command doesn't accept null value for person_id. > How to do in postgres? > > create table event > ( > event_id serial not null, > event_description char(255) , > person_id serial , > primary key (event_id), > foreign key (person_id) > references person (person_id) > ); I don't think you want to use serial type for a value that references another table. Use integer instead. Serial also implies not null which is why you couldn't stick null values into that field.