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 1fSRbc-0000Lx-2j for pgsql-general@arkaria.postgresql.org; Mon, 11 Jun 2018 18:31:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fSRba-0001uy-V8 for pgsql-general@arkaria.postgresql.org; Mon, 11 Jun 2018 18:31:50 +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 1fSRbZ-0001uo-1c for pgsql-general@lists.postgresql.org; Mon, 11 Jun 2018 18:31:50 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fSRbV-0000TZ-RP for pgsql-general@lists.postgresql.org; Mon, 11 Jun 2018 18:31:47 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id BD9A320FD4; Mon, 11 Jun 2018 14:31:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Mon, 11 Jun 2018 14:31:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=RdDMJDAREFoOrVnOVvZTltdgjFIfb mXCsr8jk4lIu5I=; b=TU7rdPJ1UYuW+3pANJrAeCszZ3HTsp6eFS2OHEaXvbcpf ljkhrv6YvIK1uhrkOtQudZNGYz6roiMX30MRKmuNGwCUzRg+mRICpH/RxRZ9U0lN Uy4Kpe3aZ4hQKtacl1hTQS9Llp7TlMMdhPPLR0372VAbiB5LfOnd240CSH4i1z37 uU1Cg/CXs/THPuEuWx9ww6n6MQBhkJ6Wg3QQTI8FlgFTtwOqiDIu6B/y7wXiGLhj fzEssr72+12GKXVAXeRj9XEFvmUQR+3Oq/Z9B6cSLraLjqbDW0de3bUUydzgow9f Rtql5rVKnMGHGJq2WzPdY6/PhuhaykeVexzGEdHkA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=RdDMJD AREFoOrVnOVvZTltdgjFIfbmXCsr8jk4lIu5I=; b=ElUN4k0htjaXHJ3Enbfyjh 3AopTj6su/3z1bXxbbYE6s8OuuyB/xNrsIf6/Bu+5WRu2A1Viupju5MGai6WBnkK piW78nxsV7H+GTiK5dbF2beNXblhfmSZlJSLMi7gYEPv7XCdwUBAEO9suzDM5LiN LxtULLiriTKJm28SA3/2rP6tk+wpvdJqEr4J3CDg8wlQkdb6Aj5W0CHYDXob/cIV 8wPQGntp/c525xD0R4PtnNFRpuSx5wY4+VT65G0Wnx57V4Y48Q9dcxB8KIg/3xBP AWruRCKlRAcuCUWFFaVKtSJVbCRbG/r6d6p68Xe4MDfBfU4+Z3M+DIVbg/SVJIqA == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id 0B4A2E4A32; Mon, 11 Jun 2018 14:31:43 -0400 (EDT) Subject: Re: Catching unique_violation exception on specific column/index To: Alexey Dokuchaev , Thomas Kellerer Cc: pgsql-general@lists.postgresql.org 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> <20180611182059.GA60559@regency.nsu.ru> From: Adrian Klaver Message-ID: <05bb9c5a-96eb-af40-c8ad-bff65a186838@aklaver.com> Date: Mon, 11 Jun 2018 11:31:42 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180611182059.GA60559@regency.nsu.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 06/11/2018 11:21 AM, Alexey Dokuchaev wrote: > 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? https://www.postgresql.org/docs/10/static/arrays.html 8.15.3. Accessing Arrays "... cardinality returns the total number of elements in an array across all dimensions. It is effectively the number of rows a call to unnest would yield: ..." > > ./danfe > -- Adrian Klaver adrian.klaver@aklaver.com