From: Adrian Klaver <adrian.klaver@aklaver.com>
To: David Gauthier <davegauthierpg@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Need a referential constraint to a non-unique record
Date: Thu, 27 Jun 2019 14:46:52 -0700
Message-ID: <3f36f68f-5fbf-74d4-350f-0dcb9f647c76@aklaver.com> (raw)
In-Reply-To: <CAMBRECBG=3PyyoZCQUPv3t2Ak93JZVBRGKBDx0zFUAP6vHSWYg@mail.gmail.com>
References: <CAMBRECCAS-Ka3zPTNuy6oM=+vfeH3kPqeibuDahY5P73z4zPjA@mail.gmail.com>
<37267c00-86b5-e17d-f667-99cb2968c2a9@aklaver.com>
<CAMBRECBG=3PyyoZCQUPv3t2Ak93JZVBRGKBDx0zFUAP6vHSWYg@mail.gmail.com>
On 6/26/19 7:28 AM, David Gauthier wrote:
Ccing list.
> Actually, I'm not storing 4 records in the 'grades' table for each
> record in the 'students' table. For example, if student Joe gets
> straight A's, he points to grades.grade_id = 1. If student Sue also
> gets straight A's, she points to grades.grade_id = 1. I'm reusing the
> set of records in "grades" for >1 student. It's not a situation where
> there's a "student_id" field in the "grades" table which points to a
> "student_id" (PK) field in the "students" table with a FK relationship.
>
> This simplistic example is not what's going on in my real application
> where the equivalent of the "grades" table has hundreds of records and
> there are thousands of "students". I don't want to have to duplicate
> the set of "grades" records over and over again if an existing set can
> be "reused".
Hmm.
1) So each 'student' has to take all the 'subjects'?
If not then what happens?
2) You have to pre-plan all the possible combinations.
What happens if a 'subject' is added/deleted?
3) Your app has to 'know' what id points to what combination.
I see the above as resistant to change and fragile and as you already
have determined hard to model. I'm thinking a more traditional layout
will be better over the long run.
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, davegauthierpg@gmail.com
Subject: Re: Need a referential constraint to a non-unique record
In-Reply-To: <3f36f68f-5fbf-74d4-350f-0dcb9f647c76@aklaver.com>
References: <CAMBRECCAS-Ka3zPTNuy6oM=+vfeH3kPqeibuDahY5P73z4zPjA@mail.gmail.com> <37267c00-86b5-e17d-f667-99cb2968c2a9@aklaver.com> <CAMBRECBG=3PyyoZCQUPv3t2Ak93JZVBRGKBDx0zFUAP6vHSWYg@mail.gmail.com> <3f36f68f-5fbf-74d4-350f-0dcb9f647c76@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox