From: | David Johnston <polobo(at)yahoo(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: *Proper* solution for 1..* relationship? |
Date: | 2013-04-26 12:55:05 |
Message-ID: | 1366980905007-5753392.post@n5.nabble.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Broersma | 2013-04-26 14:13:07 | Re: *Proper* solution for 1..* relationship? |
Previous Message | Wolfgang Keller | 2013-04-26 11:59:11 | *Proper* solution for 1..* relationship? |