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 1erVMb-0002Ip-FY for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 21:03:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erVMY-0001iH-Ss for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 21:03:38 +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 1erVMY-0001i2-Kk for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 21:03:38 +0000 Received: from eastrmfepo202.cox.net ([68.230.241.217]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erVMW-0003aa-0N for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 21:03:38 +0000 Received: from eastrmimpo109.cox.net ([68.230.241.222]) by eastrmfepo202.cox.net (InterMail vM.8.01.05.28 201-2260-151-171-20160122) with ESMTP id <20180301210334.JROA7489.eastrmfepo202.cox.net@eastrmimpo109.cox.net> for ; Thu, 1 Mar 2018 16:03:34 -0500 Received: from [192.168.1.10] ([70.171.109.83]) by eastrmimpo109.cox.net with cox id Gl3Z1x01M1o04Vy01l3a6E; Thu, 01 Mar 2018 16:03:34 -0500 X-Authority-Analysis: v=2.2 cv=bLhmGL2Z c=1 sm=1 tr=0 a=uCHdjGDeLqaieW9t8IbZ6A==:117 a=uCHdjGDeLqaieW9t8IbZ6A==:17 a=x7bEGLp0ZPQA:10 a=T11QR6bd6vIA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=kviXuzpPAAAA:8 a=t4sAoOPkAcD0wQGLuyEA:9 a=Yoj9ju-sUo78OM29:21 a=NB3kEshH7YnwazHd:21 a=QEXdDO2ut3YA:10 a=pGLkceISAAAA:8 a=qV4dC7IFuysK2wcyNSwA:9 a=Rj9_R3oL41wF-Ama:21 a=XXKCmEaOSTI65bFp:21 a=LNfQbonFst7hVtL8:21 a=_W_S_7VecoQA:10 a=qrIFiuKZe2vaD64auk6j: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-general@lists.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: <87230ccb-5b8e-e4ee-d6d5-63a9cbac5793@cox.net> Date: Thu, 1 Mar 2018 15:03:33 -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="------------94920379208B6F9786BA9451" 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. --------------94920379208B6F9786BA9451 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 03/01/2018 02: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. There's always the "account number", which is usually synthetic. Credit Card numbers are also synthetic.  ICD numbers are (relatively) synthetic, too. But that doesn't mean we have to use them willy-nilly everywhere. -- Angular momentum makes the world go 'round. --------------94920379208B6F9786BA9451 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 03/01/2018 02:32 PM, David G. Johnston 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.

There's always the "account number", which is usually synthetic.  Credit Card numbers are also synthetic.  ICD numbers are (relatively) synthetic, too.

But that doesn't mean we have to use them willy-nilly everywhere.


--
Angular momentum makes the world go 'round.
--------------94920379208B6F9786BA9451--