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 1fSR7y-000683-8m for pgsql-general@arkaria.postgresql.org; Mon, 11 Jun 2018 18:01:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fSR7w-00061Q-Ls for pgsql-general@arkaria.postgresql.org; Mon, 11 Jun 2018 18:01:12 +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 1fSR7w-00061H-E7 for pgsql-general@lists.postgresql.org; Mon, 11 Jun 2018 18:01:12 +0000 Received: from mx.nsu.ru ([84.237.50.39]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fSR7t-0001Qd-6D for pgsql-general@lists.postgresql.org; Mon, 11 Jun 2018 18:01:11 +0000 Received: from Debian-exim by mx.nsu.ru with local (Exim 4.72) (envelope-from ) id 1fSR7p-0006Lr-7o for pgsql-general@lists.postgresql.org; Tue, 12 Jun 2018 01:01:05 +0700 Received: from [84.237.50.47] (helo=regency.nsu.ru) by mx.nsu.ru with esmtp (Exim 4.72) (envelope-from ) id 1fSR7o-0006LY-Vg; Tue, 12 Jun 2018 01:01:05 +0700 Received: from regency.nsu.ru (localhost [127.0.0.1]) by regency.nsu.ru (8.14.2/8.14.2) with ESMTP id w5BIL5Rc063162; Tue, 12 Jun 2018 00:21:05 +0600 (NOVT) (envelope-from danfe@regency.nsu.ru) Received: (from danfe@localhost) by regency.nsu.ru (8.14.2/8.14.2/Submit) id w5BIL0B5063149; Tue, 12 Jun 2018 01:21:00 +0700 (+07) (envelope-from danfe) Date: Tue, 12 Jun 2018 01:21:00 +0700 From: Alexey Dokuchaev To: Thomas Kellerer Cc: pgsql-general@lists.postgresql.org Subject: Re: Catching unique_violation exception on specific column/index Message-ID: <20180611182059.GA60559@regency.nsu.ru> References: <20180611101033.GA40332@regency.nsu.ru> <0fa3bd50-3ce2-2038-29da-48fa0a1f6b19@gmx.net> <20180611105834.GA47390@regency.nsu.ru> <6ccb6712-33bb-2f42-c16f-378a337160b6@gmx.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6ccb6712-33bb-2f42-c16f-378a337160b6@gmx.net> User-Agent: Mutt/1.4.2.1i X-KLMS-Rule-ID: 3 X-KLMS-Message-Action: skipped X-KLMS-AntiSpam-Status: not scanned, whitelist X-KLMS-AntiPhishing: not scanned, whitelist X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server, version 8.0.1.705, not scanned, whitelist List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Jun 11, 2018 at 01:26:16PM +0200, Thomas Kellerer wrote: > 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. Oh well, fair enough. As much as I'd love to stick to the lowest supported (and sometimes even unsupported) versions, ON CONFLICT is indeed very handy, esp. since I have a few UPSERT's implemented the old way already (via catching the "unique_violation" exception). Shall I update to 9.6/10, I have a bit off-topic (to the original subject) question: right now, when I need to get the length of an array (never multidimensional), I do this: coalesce(array_length(foo, 1), 0); In 9.4+, I can call cardinality(). I'm a bit hesitant: is doing so semantically correct, or should I still do coalesce(..., 0) in this case? This is not about the outcome, it's whether cardinality() is semantically correct to obtain the number of the array items, or it was introduced for other means? ./danfe