Re: There can be only one! How to avoid the "highlander-problem". - Mailing list pgsql-general

From Erwin Brandstetter
Subject Re: There can be only one! How to avoid the "highlander-problem".
Date
Msg-id 1181051250.451168.313210@q69g2000hsb.googlegroups.com
Whole thread Raw
In response to There can be only one! How to avoid the "highlander-problem".  (Erwin Brandstetter <brandstetter@falter.at>)
List pgsql-general
On Jun 5, 5:10 am, Lew <l...@nospam.lewscanon.com> wrote:
> Erwin Brandstetter wrote:
> > CREATE TABLE king
> > (
> >    king_id INTEGER PRIMARY KEY REFERENCES man (man_id) ON UPDATE
> > CASCADE ON DELETE CASCADE,
> >    nation_id INTEGER UNIQUE,
> >    FOREIGN KEY (man_id, nation_id) REFERENCES man (man_id, nation_id)
> > ON UPDATE CASCADE ON DELETE CASCADE
> > );
>
> I like this.

On Jun 5, 5:10 am, Lew <l...@nospam.lewscanon.com> wrote:
> Erwin Brandstetter wrote:
> > CREATE TABLE king
> > (
> >    king_id INTEGER PRIMARY KEY REFERENCES man (man_id) ON UPDATE
> > CASCADE ON DELETE CASCADE,
> >    nation_id INTEGER UNIQUE,
> >    FOREIGN KEY (man_id, nation_id) REFERENCES man (man_id, nation_id)
> > ON UPDATE CASCADE ON DELETE CASCADE
> > );
>
> I like this.

On a second inspection, I had a typo in the code above, and the second
foreign key is redundant. So we get:

CREATE TABLE king
(
   man_id INTEGER PRIMARY KEY,
   nation_id INTEGER UNIQUE,
   FOREIGN KEY (man_id, nation_id) REFERENCES man (man_id, nation_id)
ON UPDATE CASCADE ON DELETE CASCADE
);

(...)
> > We are still avoiding circular references.
>
> I'm not so sure we need to avoid that.

Yeah, I don't think we have to avoid it. But as it comes at no cost,
I'd take it. I have commented on possible complications arising from
circular references above.

Regards
Erwin


pgsql-general by date:

Previous
From: Ron Johnson
Date:
Subject: Re: Database design wisdom needed
Next
From: Andrew Sullivan
Date:
Subject: Re: Database design wisdom needed