Re: *Proper* solution for 1..* relationship? - Mailing list pgsql-novice

From David Johnston
Subject Re: *Proper* solution for 1..* relationship?
Date
Msg-id 1366980905007-5753392.post@n5.nabble.com
Whole thread Raw
In response to *Proper* solution for 1..* relationship?  (Wolfgang Keller <feliphil@gmx.net>)
List pgsql-novice
Wolfgang Keller-2 wrote
> It hit me today that a 1..* relationship can't be implemented just by a
> single foreign key constraint. I must have been sleeping very deeply not
> to notice this.
>
> E.g. there is a table "list" and another table "list_item" and the
> relationship can be described as "every list has at least one
> list_item" (and every list_item can only be part of one list, but
> this is trivial).

Change the cardinality to "0..*" ?

If you want to enforce a view of the data the ensures "1..*" (for list) then
create a view of "list" where only those entries with values in "list_item"
are shown.

Alternately you might simply add a counter column to the list table and use
triggers to increment/decrement the "item_count".

David J.





--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Proper-solution-for-1-relationship-tp5753384p5753392.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


pgsql-novice by date:

Previous
From: Wolfgang Keller
Date:
Subject: *Proper* solution for 1..* relationship?
Next
From: Richard Broersma
Date:
Subject: Re: *Proper* solution for 1..* relationship?