Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jFN2c-0006fL-7O for pgsql-general@arkaria.postgresql.org; Fri, 20 Mar 2020 19:10:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jFN2Z-0002wc-SW for pgsql-general@arkaria.postgresql.org; Fri, 20 Mar 2020 19:10:43 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1jFN2Y-0002wU-Sv for pgsql-general@lists.postgresql.org; Fri, 20 Mar 2020 19:10:43 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jFN2U-0005rS-Kr for pgsql-general@lists.postgresql.org; Fri, 20 Mar 2020 19:10:42 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id EDA825C0295; Fri, 20 Mar 2020 15:10:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 20 Mar 2020 15:10:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=Z IW0xnik74cMM7HqUmCOVP3eMjz//z6oM2hSaTRpjFw=; b=M4o+DRJX6//3zky3q fv7wpnvCd54ICXs38PjnHoqZTHXGRdLC7SBK2O+TLKM0k1SBHrJFZz+UrBCKljCC kEu3azFLE+DsOg3hbCFcKLDJEfsi1dVF/5e3PTuLINBImNQSCZZ9yDOoCH2X+2Bv qdmyjZyFb96apAATajOxf/FoHGHAdGZ8oHdKpycjQrL8wOR9ndidXC6gRdyZg4I3 quLYtApncSa9ttjfv+2NE2y/hS6rUkcIPhO9IVm8kZa2idAFbQ3DWh0dNN0l3rl0 OXYnjXnfaV6nC3tv5F13U9yfXoBBSf3SmFfQDVk/ngqdI1I+fauq9kke5nvffGol R7u9w== 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-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=ZIW0xnik74cMM7HqUmCOVP3eMjz//z6oM2hSaTRpj Fw=; b=Jzb82tdbh+k2hXKqAkmUmY3Ee5nhIziwO3drowMoY1OVMU4za6tQA3x4g ejstJk59kCQNf1oNQrTBLuH4xZ2aPBIaVU9lwL+DYLCw3P9yMIR295b9JK5sAnRq toKRMAoh54ki83YqyOlJt4cP+ot3TKkcJDmKgp9j+PADlPJKRK+pad1xT869AQTA yyLSIJsAnQmwVCS/4GPh7i4+9IdS1pKOXgjLIm02rANsUpwAhTUTkv12iyybS6yG qoWpqf97JywlPzU3cxHgH9jSyC3tqRiAFFx4VWeQCv+OkqwRisYRGQ9YSRYBH1Kw 8VfmhXcor+De/9zae4YMxcp+xybhw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudeguddguddvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesth ekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepphhoshhtghhrvg hsqhhlrdhorhhgnecukfhppeejuddrvdduvddruddvledrudelfeenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvg hrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id 467AB328005A; Fri, 20 Mar 2020 15:10:35 -0400 (EDT) Subject: Re: Duplicate key violation on upsert To: Matt Magoffin Cc: pgsql-general@lists.postgresql.org References: <0E4E069D-40B1-46C1-9BA0-5A5E737F753B@msqr.us> <604644e7-6881-3fdb-8767-897fc40559ac@aklaver.com> <03EC7E36-EA7F-452A-B0A9-2F0FBB73E914@msqr.us> From: Adrian Klaver Message-ID: <00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com> Date: Fri, 20 Mar 2020 12:10:34 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <03EC7E36-EA7F-452A-B0A9-2F0FBB73E914@msqr.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/20/20 11:34 AM, Matt Magoffin wrote: > > >> On 21/03/2020, at 4:00 AM, Adrian Klaver > > wrote: >> >> On 3/20/20 2:17 AM, Matt Magoffin wrote: >>> Hello, >>> Indexes: >>>     "da_datum_pkey" UNIQUE, btree (node_id, ts, source_id) CLUSTER, >>> tablespace "solarindex" >>>     "da_datum_reverse_pkey" UNIQUE, btree (node_id, ts DESC, >>> source_id), tablespace "solarindex" >>>     "da_datum_x_acc_idx" UNIQUE, btree (node_id, source_id, ts DESC, >>> jdata_a) WHERE jdata_a IS NOT NULL, tablespace "solarindex" >>> The error/query looks like: >>> ERROR: duplicate key value violates unique constraint >>> “_hyper_1_1931_chunk_da_datum_x_acc_idx" >> >> What is the above index UNIQUE over? >> >> What is da_datum_x_acc_idx index below indexed over? > > The _hyper_1_1931_chunk_da_datum_x_acc_idx index has the same definition > as the da_datum_x_acc_idx above (it is defined on a child table). That > is, they are both essentially: > > UNIQUE, btree (node_id, source_id, ts DESC, jdata_a) WHERE jdata_a IS > NOT NULL > > The da_datum_pkey index is what the ON CONFLICT cause refers to, so > (node_id, ts, source_id) is UNIQUE as well. Hmm, wonder if you are getting bit by this?: https://www.postgresql.org/docs/12/sql-insert.html#SQL-ON-CONFLICT "INSERT with an ON CONFLICT DO UPDATE clause is a “deterministic” statement. This means that the command will not be allowed to affect any single existing row more than once; a cardinality violation error will be raised when this situation arises. Rows proposed for insertion should not duplicate each other in terms of attributes constrained by an arbiter index or constraint." > > — m@ > -- Adrian Klaver adrian.klaver@aklaver.com