Re: null foreign key column

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Arunachalam Jaisankar <jsankar(at)xtra(dot)co(dot)nz>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: null foreign key column
Date: 2003-02-12 20:41:09
Message-ID: 20030212204109.GB30483@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, Feb 11, 2003 at 16:55:28 +1300,
Arunachalam Jaisankar <jsankar(at)xtra(dot)co(dot)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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Larry Rosenman 2003-02-12 20:45:42 Re: timestamp
Previous Message Dmitry Tkach 2003-02-12 20:39:03 Re: How do you select from a table until a condition is met?