Re: null foreign key column

From: Dmitry Tkach <dmitry(at)openratings(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: null foreign key column
Date: 2003-02-12 22:24:49
Message-ID: b2ebqi$9eb$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

You don't want it to be serial - just make it 'person_id in'

I hope, it helps...

Dima

Arunachalam Jaisankar wrote:
> This is a multi-part message in MIME format.
>
> ------=_NextPart_000_0005_01C2D1EE.61998D70
> Content-Type: text/plain;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> Hi all,
>
> I would like to have a foreign key column in my table which allows null val=
> ue 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)
> );
>
> regards
> Jai
> ------=_NextPart_000_0005_01C2D1EE.61998D70
> Content-Type: text/html;
> charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <HTML><HEAD>
> <META http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-8859-1">
> <META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
> <STYLE></STYLE>
> </HEAD>
> <BODY bgColor=3D#ffffff>
> <DIV><FONT face=3DArial size=3D2>Hi all,</FONT></DIV>
> <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT face=3DArial size=3D2>I would like to have a foreign key column =
> in my=20
> table which allows null value also.</FONT></DIV>
> <DIV><FONT face=3DArial size=3D2>But the below create table sql command doe=
> sn't=20
> accept null value for person_id.</FONT></DIV>
> <DIV><FONT face=3DArial size=3D2>How to do in postgres?</FONT></DIV>
> <DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial size=3D2></FONT>=
> &nbsp;</DIV>
> <DIV><FONT face=3DArial size=3D2>create table event<BR>(<BR>&nbsp;&nbsp;&nb=
> sp;=20
> event_id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
> nbsp;&nbsp;&nbsp;=20
> serial&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
> sp;&nbsp;&nbsp;&nbsp;=20
> not null,<BR>&nbsp;&nbsp;&nbsp; event_description&nbsp;&nbsp;&nbsp;&nbsp;&n=
> bsp;=20
> char(255)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
> ,<BR>&nbsp;&nbsp;&nbsp;=20
> person_id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
> &nbsp;&nbsp;=20
> serial&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
> sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
> ,<BR>&nbsp;&nbsp;&nbsp; primary key (event_id),<BR>&nbsp;&nbsp;&nbsp; forei=
> gn=20
> key&nbsp; (person_id)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; references pe=
> rson=20
> (person_id)<BR>);</FONT></DIV>
> <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
> <DIV><FONT face=3DArial size=3D2>regards</FONT></DIV>
> <DIV><FONT face=3DArial size=3D2>Jai</FONT></DIV></BODY></HTML>
>
> ------=_NextPart_000_0005_01C2D1EE.61998D70--
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Vernon Wu 2003-02-12 22:35:07 Re: null foreign key column
Previous Message Nicholas Allen 2003-02-12 22:21:18 Possible bug in Postgres? Followup to "How do you select from a table until a condition is met?"