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 1erSn4-0005Z0-Tb for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 18:18:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erSn3-0002Im-Ti for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 18:18:49 +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 1erSn3-0002Ia-M2 for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 18:18:49 +0000 Received: from eastrmfepo101.cox.net ([68.230.241.213]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erSn0-0007Sh-Hb for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 18:18:49 +0000 Received: from eastrmimpo305.cox.net ([68.230.241.237]) by eastrmfepo101.cox.net (InterMail vM.8.01.05.28 201-2260-151-171-20160122) with ESMTP id <20180301181842.ERIW11711.eastrmfepo101.cox.net@eastrmimpo305.cox.net> for ; Thu, 1 Mar 2018 13:18:42 -0500 Received: from [192.168.1.10] ([70.171.109.83]) by eastrmimpo305.cox.net with cox id GiJi1x00a1o04Vy01iJisH; Thu, 01 Mar 2018 13:18:42 -0500 X-Authority-Analysis: v=2.2 cv=ZJOnoTzb c=1 sm=1 tr=0 a=uCHdjGDeLqaieW9t8IbZ6A==:117 a=uCHdjGDeLqaieW9t8IbZ6A==:17 a=x7bEGLp0ZPQA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=3oc9M9_CAAAA:8 a=Ds8C5Z83NqSIi2_gqCEA:9 a=7Zwj6sZBwVKJAoWSPKxL6X1jA+E=:19 a=QEXdDO2ut3YA:10 a=pGLkceISAAAA:8 a=tImfLAKIf6YqzsQz0l0A:9 a=Yt_ObD38W62jR3k9:21 a=_W_S_7VecoQA:10 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> From: Ron Johnson Message-ID: <5a1870db-7018-fe15-ac60-ffe37abb7077@cox.net> Date: Thu, 1 Mar 2018 12:18:42 -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="------------BA607A7AD7B6E300055DCB3A" 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. --------------BA607A7AD7B6E300055DCB3A Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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. -- Angular momentum makes the world go 'round. --------------BA607A7AD7B6E300055DCB3A Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
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.

--
Angular momentum makes the world go 'round.
--------------BA607A7AD7B6E300055DCB3A--