Re: null foreign key column - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: null foreign key column
Date
Msg-id 20030212204109.GB30483@wolff.to
Whole thread Raw
In response to null foreign key column  ("Arunachalam Jaisankar" <jsankar@xtra.co.nz>)
List pgsql-sql
On Tue, Feb 11, 2003 at 16:55:28 +1300, Arunachalam Jaisankar <jsankar@xtra.co.nz> 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.


pgsql-sql by date:

Previous
From: Dmitry Tkach
Date:
Subject: Re: How do you select from a table until a condition is met?
Next
From: Larry Rosenman
Date:
Subject: Re: timestamp