From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Foreign keys and null |
Date: | 2003-09-29 15:46:25 |
Message-ID: | 24830.1064850385@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Oliver Fromme <olli(at)lurza(dot)secnetix(dot)de> writes:
> I wasn't aware that a foreign key actually _can_ be null.
> The docs weren't very specific about that. Thinking that
> a foreign key must contain a valid reference to another
> table (after all, that's what a foreign key is for), I
> implied that it cannot be null -- which was wrong.
If you put a NOT NULL constraint on the column along with the FOREIGN
KEY constraint, then every entry must be a valid reference. However,
in cases where you want some of the rows to have no reference, you
leave off the NOT NULL. Simple eh?
Also, if you are using multi-column foreign keys, there is a MATCH
option that determines the semantics of partially-null key sets.
But that might be getting far afield for the novice list...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Bruno Wolff III | 2003-09-29 16:01:37 | Re: Computed columns and functions? |
Previous Message | David Benoff | 2003-09-29 14:49:44 | Computed columns and functions? |