Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgcET-0005Kt-1f for pgsql-general@arkaria.postgresql.org; Thu, 27 Jun 2019 21:47:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hgcEQ-0007LD-W6 for pgsql-general@arkaria.postgresql.org; Thu, 27 Jun 2019 21:47:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgcEP-0007Fn-7O for pgsql-general@lists.postgresql.org; Thu, 27 Jun 2019 21:47:02 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hgcEK-0000qw-Ts for pgsql-general@postgresql.org; Thu, 27 Jun 2019 21:47:00 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 61BBE21C82; Thu, 27 Jun 2019 17:46:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 27 Jun 2019 17:46:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=v 3bcAoGsVceQkC9tzEVAiZPpgvfUXT2sEp3gtjnbiQo=; b=LIUp3hDql0jg0ecdk afNqIguwkri1scd4tLXUTl8sTmFlwh87KckJWUS08zC3y8CJ2jm3aRYrlPRal56N NhFdC9ZZkdqpE+0capaLhW3I6mPG2dC+3Dz9CF/qMiVl70gRBk+bPfzNr0d8HwTp yUtuXwIQz5KGMFXP0cISKO3PKNAjeBVxZjK/QFGQYHGgtDJv03NW/bmMd160yM+F xqJYzHhk+1h3fSnuEu5bGflLSI7GRCovg+LzSaz6tiQPc9J1hDl1976QoAmN7bdG 5uiRxtylm3wdq8EJa+dcndW23qBzW1VEDkgmW9YZaBsK90g3lJMcmmOxqIzrfeVe ZCOwQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=v3bcAoGsVceQkC9tzEVAiZPpgvfUXT2sEp3gtjnbi Qo=; b=z/YeN2Ta+APok+XjFx+JIBxgYm8EObYidineqicMTWV6tj3mIfyoA11GQ DCtcjEp2br8QVE1vcevw3ROBjWqbojCOozWS9ZFtlU3m5zbl1uJvO9v1lLSmtl9x b1EQF0Fq3em0aQsSbSqQWHZzIG71rQlUu+0dPNJI87GyxpE3dn1jqthEG6OyiVUh +x2UsvDeyl2SAvmZCzEfolgYHPnMi+zpGsp34HRzpoGLomZpse9Ho2AI0kYW5VB0 Q1HkZaXfykFKMqa+yeAAAnHmF/Am7a6bsKKU7vHFFhJ/WKuPtt94twbcNjZf4IPX fkbcMk65XzG/5DkQ6C3Vw/IqRq+Dw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudelgddtvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesthekre dttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhl rghvvghrsegrkhhlrghvvghrrdgtohhmqeenucfkphephedtrdduleejrdektddrvdenuc frrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgv rhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id AE38D380086; Thu, 27 Jun 2019 17:46:53 -0400 (EDT) Subject: Re: Need a referential constraint to a non-unique record To: David Gauthier References: <37267c00-86b5-e17d-f667-99cb2968c2a9@aklaver.com> Cc: pgsql-general From: Adrian Klaver Message-ID: <3f36f68f-5fbf-74d4-350f-0dcb9f647c76@aklaver.com> Date: Thu, 27 Jun 2019 14:46:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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