Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fSKxu-0003cn-G8 for pgsql-general@arkaria.postgresql.org; Mon, 11 Jun 2018 11:26:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fSKxr-00071k-Nh for pgsql-general@arkaria.postgresql.org; Mon, 11 Jun 2018 11:26:23 +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 1fSKxr-00071a-5D for pgsql-general@lists.postgresql.org; Mon, 11 Jun 2018 11:26:23 +0000 Received: from mout.kundenserver.de ([212.227.126.134]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fSKxo-0007TB-1e for pgsql-general@lists.postgresql.org; Mon, 11 Jun 2018 11:26:21 +0000 Received: from [10.8.0.146] ([185.40.248.10]) by mrelayeu.kundenserver.de (mreue002 [212.227.15.129]) with ESMTPSA (Nemesis) id 0MG2ic-1fV6OF0RiY-00Ez1p for ; Mon, 11 Jun 2018 13:26:17 +0200 Subject: Re: Catching unique_violation exception on specific column/index To: pgsql-general@lists.postgresql.org Newsgroups: gmane.comp.db.postgresql.general References: <20180611101033.GA40332@regency.nsu.ru> <0fa3bd50-3ce2-2038-29da-48fa0a1f6b19@gmx.net> <20180611105834.GA47390@regency.nsu.ru> From: Thomas Kellerer Message-ID: <6ccb6712-33bb-2f42-c16f-378a337160b6@gmx.net> Date: Mon, 11 Jun 2018 13:26:16 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 In-Reply-To: <20180611105834.GA47390@regency.nsu.ru> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:ycFhouu4VZOu0uJNV/8wWOPmcmliSEVUv0mwOR7A8vwOHoDmvPC Gd/Vl6dEB2pLdzhzOU4LOZLBZfGyKH72hpeZafp1CHbqgNC0Mk1iyWeFboW49doP9DDEwib /9h5ChDjfMfAmvVuu9oGnW42NMUXwflHHre+zza4ZHHeC6j9t+YLeJhcwU3M0SMm/IJQGes /BhggBeD/OHXOEL+7eVGQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:nxnVI0gWhio=:g0xYGjp9jo/p6VmCgbBytG wOlunK/CEe/iUliwmY9figVqUxveMu7u0I82GmHz6hK7JcHsLSLi0JGxtRIN12747ofBWbYDR gUs0LXf/3/ObwpNfyPr9vLDs1SifaAhYM6yQiSzWFyf5yF6RjsA6oBtCuVxqkHJnnoKAD5PZY nBMOy0zw/sXl85z08A2U4TgqBfNb7/hWTh2abY2fASS3mnmmNs3PrNgopMgrb4sdDq+JewuK5 guIWKCJT75FlYM4mFGuIKECUQ9H/GnX9cnNaXv5uMlZaB2bFhYXoCtx4bg0nhEkL4wl/bTY/h 6W5+Z9XI7ZnnhNl0U3VgqLmvKV4MXec1lpwp3i9Ful0rgHerFlOjHx6A9PVkw3fkEnMfmpHwn 32XjVbFmyRVZrLUrgCPe6cWxG1QqO6+K763dV0sU4oBSYWfrlXiQgwO2rTb1sn8ZQFhi4wzGX AJiQ0nVjqfVcS2C3rAy/7mTdhpFtnSzqrqqzXoNlL04kpwXVsrLxseI/ZxsW+dgAicbdVRwsI iYLm99hvTJWTisiSFPaPEKjQ2A7AzQrSIjo+pnVvWuhzvYnQgrtC/NiPReHtUuHl0qBsoBeYp d6j4PWD4o1uNKfr2fYs35EDCwJjeBuy37C6fkQE1WlQicSXgxjz6QbVPAqnoQ5GNCk7mKmmt0 /20SUXuabPBJaft5oiu4x+RsYs2R1WESzFZH5eDu3SZ/f9nIUc3u3rq0N7fiqu6Tq/uacGKgi rmlVUJR4/tnJ43l+ List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alexey Dokuchaev schrieb am 11.06.2018 um 12:58: >>> I have a table with several UNIQUE and CHECK constraints. One of these >>> UNIQUE constraints actually *can* be violated -- not on the table level, >>> of course, but on the application level -- meaning, if the entry with >>> particular foo_key is already in there, do not throw an exception, just >>> silently do nothing. >> >> What's wrong with: >> >> INSERT ... >> ON CONFLICT (foo_key) DO NOTHING > > Nothing I guess, except that it is available since 9.5 (right?), and I try > to stay compatible with 9.3. Sorry for not saying this in the first place. Andreas already mentioned that 9.3 will be EOL soon (3 months from now), but the performance and efficiency for concurrent execution of ON CONFLICT is much better than anything you can implement yourself. If that functionality is an important part of your code, you should consider upgrading to 10 (or 9.6 if your are really conservative) rather sooner than later.