Re: FOREIGN KEYs ... I think ... - Mailing list pgsql-sql

From Tom Lane
Subject Re: FOREIGN KEYs ... I think ...
Date
Msg-id 27177.1136426087@sss.pgh.pa.us
Whole thread Raw
In response to FOREIGN KEYs ... I think ...  ("Marc G. Fournier" <scrappy@postgresql.org>)
Responses Re: FOREIGN KEYs ... I think ...  ("Marc G. Fournier" <scrappy@postgresql.org>)
List pgsql-sql
"Marc G. Fournier" <scrappy@postgresql.org> writes:
> Now, what I want to do is add a FOREIGN KEY (again, I think) that when 
> incident_summary.status is changed (either closed, or reopened), the 
> associated records in incident_comments are changed to the same state ...

Why not just get rid of the status column in incident_comments, and
treat incident_summary.status as the sole copy of the state?  When you
need to get to it from incident_comments, you do a join.

The foreign key you really ought to have here is from
incident_comments.incident_id to incident_summary.id
(assuming that I've understood your schema correctly).
        regards, tom lane


pgsql-sql by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: FOREIGN KEYs ... I think ...
Next
From: "Marc G. Fournier"
Date:
Subject: Re: FOREIGN KEYs ... I think ...