From: | Jan Wieck <JanWieck(at)Yahoo(dot)com> |
---|---|
To: | gearond(at)cvc(dot)net |
Cc: | tom dyson <tom(at)torchbox(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: conditional constraints |
Date: | 2003-04-11 15:33:50 |
Message-ID: | 3E96E05E.DC64A25C@Yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Dennis Gearon wrote:
>
> Also, (I would love to be corrected nicely if I'm wrong), a column can be
> NULL'able and have a foreign contraint on it, and have NULL values, right?
Right!
That's exactly where the wrong assumption was. A FOREIGN KEY does not
require a NOT NULL (a PRIMARY KEY implies that). Foreign key columns
filled with NULLs are absolutely valid and are not considered a breach
of integrity.
Jan
>
> Jan Wieck wrote:
> > tom dyson wrote:
> >
> >>(on behalf of my colleague, Neal Todd)
> >>
> >>This question is about whether it's possible to have conditionality on a
> >>constraint, or rather (presuming it's not possible), how it can be emulated
> >>perhaps with a trigger.
> >>
> >>The scenario is this (but is fairly general anyway)...
> >>
> >>Table "P" storing projects with a project id primary key.
> >>and
> >>Table "D" storing diary entries relating to projects with foreign key
> >>constraint referencing project ids in table "P".
> >>
> >>Fine so far, we have referential integrity on the project ids in table "D".
> >>
> >>However, we need to add diary entries that are for a generic "non-project"
> >>category. Without the constraint we could just have a null or dummy (e.g. 0)
> >>entry in D's project id foreign key. But with the constraint the referential
> >>integrity is broken.
> >
> >
> > Your assumption is wrong. That's the strange thing about NULL values, we
> > can't tell what they are made of or where they are coming from, but we
> > certainly know what they are good for :-)
> >
> >
> > Jan
> >
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #
From | Date | Subject | |
---|---|---|---|
Next Message | Ed L. | 2003-04-11 15:46:55 | Re: Batch replication ordering (was Re: [GENERAL] 32/64-bit |
Previous Message | Dennis Gearon | 2003-04-11 15:26:34 | Re: conditional constraints |