Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1erVIc-0001qV-T4 for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 20:59:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erVIb-00050t-Hq for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 20:59:33 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1erVIb-00050j-9r for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 20:59:33 +0000 Received: from eastrmfepo103.cox.net ([68.230.241.215]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erVIY-0003Qn-4a for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 20:59:32 +0000 Received: from eastrmimpo110.cox.net ([68.230.241.223]) by eastrmfepo103.cox.net (InterMail vM.8.01.05.28 201-2260-151-171-20160122) with ESMTP id <20180301205926.JQVO22712.eastrmfepo103.cox.net@eastrmimpo110.cox.net> for ; Thu, 1 Mar 2018 15:59:26 -0500 Received: from [192.168.1.10] ([70.171.109.83]) by eastrmimpo110.cox.net with cox id GkzR1x00l1o04Vy01kzSzF; Thu, 01 Mar 2018 15:59:26 -0500 X-Authority-Analysis: v=2.2 cv=dfbw5Tfe c=1 sm=1 tr=0 a=uCHdjGDeLqaieW9t8IbZ6A==:117 a=uCHdjGDeLqaieW9t8IbZ6A==:17 a=x7bEGLp0ZPQA:10 a=T11QR6bd6vIA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=pGLkceISAAAA:8 a=kviXuzpPAAAA:8 a=NvJIefd1AAAA:8 a=CzzU1AsKp4oiOFM_QpAA:9 a=8i9BrFKhIPZz6u3S:21 a=4BPzuYN86aOWEHMW:21 a=QEXdDO2ut3YA:10 a=IGZ59_0IrDwA:10 a=hWLgxkZ8fC0A:10 a=MI6sqLEMzO8JTcw5GK8A:9 a=CVSUL4rNX7Xz9-Yo:21 a=hDkzWgX3U1ufAb9x:21 a=Y0CbJIswZsk2CiwL:21 a=_W_S_7VecoQA:10 a=qrIFiuKZe2vaD64auk6j:22 a=Z11pERy037KCMjAKJWwP:22 X-CM-Score: 0.00 Authentication-Results: cox.net; auth=pass (PLAIN) smtp.auth=ron.l.johnson@cox.net Subject: Re: Enforce primary key on every table during dev? To: "pgsql-generallists.postgresql.org" References: <161e1761560-58a6-18e4b@webjas-vad211.srv.aolmail.net> <5a1870db-7018-fe15-ac60-ffe37abb7077@cox.net> <5da96fe6-666b-1107-ee76-b464417bd1b7@cox.net> <80d9a83d-fbf4-e4fa-9ccf-9272a074c50d@cox.net> From: Ron Johnson Message-ID: <835e093f-6cc3-c816-7842-f49db4d1bf2f@cox.net> Date: Thu, 1 Mar 2018 14:59:25 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------33BCCEAF25068B205CFC017C" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------33BCCEAF25068B205CFC017C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 03/01/2018 02:44 PM, Daevor The Devoted wrote: > > > On Thu, Mar 1, 2018 at 10:32 PM, David G. Johnston > > wrote: > > On Thu, Mar 1, 2018 at 1:24 PM, Ron Johnson >wrote: > > Why have the overhead of a second unique index?  If it's "ease of > joins", then I agree with Francisco Olarte and use the business > logic keys in your joins even though it's a bit of extra work. > > > ​The strongest case, for me, when a surrogate key is highly desirable > is when there is no truly natural key and the best key for the model > is potentially alterable.  Specific, the "name" of something.  If I > add myself to a database and make name unique, so David Johnston, then > someone else comes along with the same name and now I want to add the > new person as, say David A. Johnston AND rename my existing record to > David G. Johnston.  I keep the needed uniqueness ​and don't need to > cobble together other data elements.  Or, if I were to use email > address as the key the same physical entity can now change their > address without me having to cascade update all FK instances too. > Avoiding the FK cascade when enforcing a non-ideal PK is a major good > reason to assign a surrogate. > > David J. > > > This is exactly my point: you cannot know when a Business Rule is going to > change. Consider, for example, your Social Security number (or ID number > as we call it in South Africa). This is unique, right?. No, the SSN is not unique. https://www.computerworld.com/article/2552992/it-management/not-so-unique.html > Tomorrow, however, data of people from multiple countries gets added to > your DB, and BAM! that ID number is suddenly no longer unique. Business > Rules can and do change, and we do not know what may change in the future. > Hence, it is safest to have the surrogate in place from the start, and > avoid the potential migraine later on. > > Disclaimer: this is just my opinion based on my experience (and the pain I > had to go through when Business Rules changed). I have not done any > research or conducted any studies on this. -- Angular momentum makes the world go 'round. --------------33BCCEAF25068B205CFC017C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 03/01/2018 02:44 PM, Daevor The Devoted wrote:


On Thu, Mar 1, 2018 at 10:32 PM, David G. Johnston <david.g.johnston@gmail.com> wrote:
On Thu, Mar 1, 2018 at 1:24 PM, Ron Johnson <ron.l.johnson@cox.net> wrote:
Why have the overhead of a second unique index?  If it's "ease of joins", then I agree with Francisco Olarte and use the business logic keys in your joins even though it's a bit of extra work.

​The strongest case, for me, when a surrogate key is highly desirable is when there is no truly natural key and the best key for the model is potentially alterable.  Specific, the "name" of something.  If I add myself to a database and make name unique, so David Johnston, then someone else comes along with the same name and now I want to add the new person as, say David A. Johnston AND rename my existing record to David G. Johnston.  I keep the needed uniqueness ​and don't need to cobble together other data elements.  Or, if I were to use email address as the key the same physical entity can now change their address without me having to cascade update all FK instances too.  Avoiding the FK cascade when enforcing a non-ideal PK is a major good reason to assign a surrogate.

David J.


This is exactly my point: you cannot know when a Business Rule is going to change. Consider, for example, your Social Security number (or ID number as we call it in South Africa). This is unique, right?.

No, the SSN is not unique.  https://www.computerworld.com/article/2552992/it-management/not-so-unique.html

Tomorrow, however, data of people from multiple countries gets added to your DB, and BAM! that ID number is suddenly no longer unique. Business Rules can and do change, and we do not know what may change in the future. Hence, it is safest to have the surrogate in place from the start, and avoid the potential migraine later on.

Disclaimer: this is just my opinion based on my experience (and the pain I had to go through when Business Rules changed). I have not done any research or conducted any studies on this.


--
Angular momentum makes the world go 'round.
--------------33BCCEAF25068B205CFC017C--