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 1erTR4-0000Zh-3X for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 19:00:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erTR2-0003fg-De for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 19:00:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1erTR2-0003fJ-26 for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 19:00:08 +0000 Received: from eastrmfepo201.cox.net ([68.230.241.216]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erTQz-0000R0-Im for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 19:00:06 +0000 Received: from eastrmimpo109.cox.net ([68.230.241.222]) by eastrmfepo201.cox.net (InterMail vM.8.01.05.28 201-2260-151-171-20160122) with ESMTP id <20180301190004.FPZP1466.eastrmfepo201.cox.net@eastrmimpo109.cox.net> for ; Thu, 1 Mar 2018 14:00:04 -0500 Received: from [192.168.1.10] ([70.171.109.83]) by eastrmimpo109.cox.net with cox id Gj031x00c1o04Vy01j037T; Thu, 01 Mar 2018 14:00:03 -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=3oc9M9_CAAAA:8 a=aitrvXIMAW1Ufwol3IsA:9 a=7Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19 a=QEXdDO2ut3YA:10 a=pGLkceISAAAA:8 a=kyr8YovSMBFtnBJh3FcA:9 a=4YYoiZoihSxq5OPy: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> From: Ron Johnson Message-ID: <5da96fe6-666b-1107-ee76-b464417bd1b7@cox.net> Date: Thu, 1 Mar 2018 13:00:03 -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="------------6F10F4A053F6634BEEDE12BB" 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. --------------6F10F4A053F6634BEEDE12BB Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 03/01/2018 12:32 PM, Daevor The Devoted wrote: > > > On Thu, Mar 1, 2018 at 8:18 PM, Ron Johnson > wrote: > > > On 03/01/2018 11:47 AM, Daevor The Devoted wrote: >> >> On Thu, Mar 1, 2018 at 2:07 PM, Rakesh Kumar > > wrote: >> >> >> >Adding a surrogate key to such a table just adds overhead, >> although that could be useful >> >in case specific rows need updating or deleting without also >> modifying the other rows with >> >that same data - normally, only insertions and selections happen >> on such tables though, >> >and updates or deletes are absolutely forbidden - corrections >> happen by inserting rows with >> >an opposite transaction. >> >> I routinely add surrogate keys like serial col to a table already >> having a nice candidate keys >> to make it easy to join tables.  SQL starts looking ungainly when >> you have a 3 col primary >> key and need to join it with child tables. >> >> >> I was always of the opinion that a mandatory surrogate key (as you >> describe) is good practice. >> Sure there may be a unique key according to business logic (which may >> be consist of those "ungainly" multiple columns), but guess what, >> business logic changes, and then you're screwed! > > And so you drop the existing index and build a new one. I've done it > before, and I'll do it again. > >> So using a primary key whose sole purpose is to be a primary key >> makes perfect sense to me. > > I can't stand synthetic keys.  By their very nature, they're so > purposelessly arbitrary, and allow you to insert garbage into the table. > > > Could you perhaps elaborate on how a surrogate key allows one to insert > garbage into the table? I'm afraid I don't quite get what you're saying. If your only unique index is a synthetic key, then you can insert the same "business data" multiple times with different synthetic keys. -- Angular momentum makes the world go 'round. --------------6F10F4A053F6634BEEDE12BB Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 03/01/2018 12:32 PM, Daevor The Devoted wrote:


On Thu, Mar 1, 2018 at 8:18 PM, Ron Johnson <ron.l.johnson@cox.net> wrote:

On 03/01/2018 11:47 AM, Daevor The Devoted wrote:

On Thu, Mar 1, 2018 at 2:07 PM, Rakesh Kumar <rakeshkumar464@aol.com> wrote:

>Adding a surrogate key to such a table just adds overhead, although that could be useful
>in case specific rows need updating or deleting without also modifying the other rows with
>that same data - normally, only insertions and selections happen on such tables though,
>and updates or deletes are absolutely forbidden - corrections happen by inserting rows with
>an opposite transaction.

I routinely add surrogate keys like serial col to a table already having a nice candidate keys
to make it easy to join tables.  SQL starts looking ungainly when you have a 3 col primary
key and need to join it with child tables.


I was always of the opinion that a mandatory surrogate key (as you describe) is good practice.
Sure there may be a unique key according to business logic (which may be consist of those "ungainly" multiple columns), but guess what, business logic changes, and then you're screwed!

And so you drop the existing index and build a new one.  I've done it before, and I'll do it again.

So using a primary key whose sole purpose is to be a primary key makes perfect sense to me.

I can't stand synthetic keys.  By their very nature, they're so purposelessly arbitrary, and allow you to insert garbage into the table.

Could you perhaps elaborate on how a surrogate key allows one to insert garbage into the table? I'm afraid I don't quite get what you're saying.

If your only unique index is a synthetic key, then you can insert the same "business data" multiple times with different synthetic keys.


--
Angular momentum makes the world go 'round.
--------------6F10F4A053F6634BEEDE12BB--