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 1erTbs-0001Rm-1e for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 19:11:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1erTbq-0000kx-7T for pgsql-general@arkaria.postgresql.org; Thu, 01 Mar 2018 19:11:18 +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 1erTbp-0000ko-LX for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 19:11:18 +0000 Received: from mail-qt0-x232.google.com ([2607:f8b0:400d:c0d::232]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1erTbm-0000kx-CP for pgsql-general@lists.postgresql.org; Thu, 01 Mar 2018 19:11:16 +0000 Received: by mail-qt0-x232.google.com with SMTP id n12so8950449qtl.5 for ; Thu, 01 Mar 2018 11:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=qdJQ1uqZVsWEFj09I6wNX68+a0VxVzCwxHDQPtp3dvk=; b=J1QgAS09sGOtDfIfKPCsqeGkQNFk4lG6hUxeuWh9nBViBAlNCdLjeINdKJRUC9P9bS FSkOIsZWqjmWM1r8iHFi7uZVKh5FeApXaC6cenmAyzW9sTjPX3H8lVxoYvnJ9NBLtDk/ 7g4jQIFGiiZrvGD6Z9VefkHKjanYRHE1+r8D6dpGNTJxWieRsimW6h9dFY27akQb7wKs UJmOm2gTaHPOxpWz/QAKSO6WClFj9UfbNYBcDTr43mXkcQz7mC9X5Uoo/uEbUEP6pNeP RCH05jErfGLUqlqaLv7IDhYS0g9+F1Zd5Y7lIPIULfNsh661VbQuPeHRK5w2lvcYfB/B zFRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=qdJQ1uqZVsWEFj09I6wNX68+a0VxVzCwxHDQPtp3dvk=; b=RSnDHweZZXiR4euHkPa8931F3mNK7zurpa24zAX7PhdEADDve1m8QPNOWva381PNgk zkgFQF0FRMn2/fxsWwOwwDB3P+kXD/mSpOxYfsw242n+KB6MXJ6muSQwRFr7ZiSchvVq 6rPWgaBOrwexRx1rJb53r2as6d+7VjAKdEP6nze6M85OfDVIG/jw3oZLxXpnwF91sy5z f6ruS8YXk7ziCVqtS6qUN92bmAk9ibFmsp7nb1r6q9HWP0gfdxtIGBJYVd3ow3Bbypbx jGoaoL2QtWXLaU9sFYVaD9VOgxjoOx2J9lctjwOZ8WgCM3J+xXdkKp7k2MOvozvbQ1XC GLsQ== X-Gm-Message-State: AElRT7ED/tzgJ1URzD7kgMi6BJdHyyt0q0+6qTghInQMaZIyOC6CPUB2 KdWYYDQ0QSNwFG6c17R0opnevUpc X-Google-Smtp-Source: AG47ELvnjQw7wQIIiwWYf1dglnVugT8AlOlGbe29mdxwVeAwgMisChGEzLZ1clDwS59eQycCZnmGPg== X-Received: by 10.237.39.38 with SMTP id n35mr4639976qtd.327.1519931472907; Thu, 01 Mar 2018 11:11:12 -0800 (PST) Received: from [192.168.1.250] (host63.190-229-77.telecom.net.ar. [190.229.77.63]) by smtp.gmail.com with ESMTPSA id b29sm3153316qkb.28.2018.03.01.11.11.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 11:11:12 -0800 (PST) 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> From: marcelo Message-ID: Date: Thu, 1 Mar 2018 16:11:09 -0300 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <5da96fe6-666b-1107-ee76-b464417bd1b7@cox.net> Content-Type: multipart/alternative; boundary="------------E534DCE6E554282A876BA595" Content-Language: en-US X-Antivirus: Avast (VPS 180228-6, 28/02/2018), Outbound message X-Antivirus-Status: Clean List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------E534DCE6E554282A876BA595 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 01/03/2018 16:00 , Ron Johnson wrote: > 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. IMHO, business logic can and must preclude "garbage insertion". Except you are inserting data directly to database using SQL, any n-tier architecture will be checking data validity. --- El software de antivirus Avast ha analizado este correo electrónico en busca de virus. https://www.avast.com/antivirus --------------E534DCE6E554282A876BA595 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
On 01/03/2018 16:00 , Ron Johnson wrote:
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.
IMHO, business logic can and must preclude "garbage insertion". Except you are inserting data directly to database using SQL, any n-tier architecture will be checking data validity.



Avast logo

El software de antivirus Avast ha analizado este correo electrónico en busca de virus.
www.avast.com


--------------E534DCE6E554282A876BA595--