pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Matt Magoffin <postgresql.org@msqr.us>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Duplicate key violation on upsert
Date: Fri, 20 Mar 2020 12:10:34 -0700
Message-ID: <00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com> (raw)
In-Reply-To: <03EC7E36-EA7F-452A-B0A9-2F0FBB73E914@msqr.us>
References: <0E4E069D-40B1-46C1-9BA0-5A5E737F753B@msqr.us>
	<604644e7-6881-3fdb-8767-897fc40559ac@aklaver.com>
	<03EC7E36-EA7F-452A-B0A9-2F0FBB73E914@msqr.us>

On 3/20/20 11:34 AM, Matt Magoffin wrote:
> 
> 
>> On 21/03/2020, at 4:00 AM, Adrian Klaver <adrian.klaver@aklaver.com 
>> <mailto:adrian.klaver@aklaver.com>> 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





view thread (15+ messages)  latest in thread

Message-ID: <00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com>
Permalink:  ../00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com/
Also on:    postgresql.org/message-id/00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, postgresql.org@msqr.us
  Subject: Re: Duplicate key violation on upsert
  In-Reply-To: <00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com>
  References: <0E4E069D-40B1-46C1-9BA0-5A5E737F753B@msqr.us> <604644e7-6881-3fdb-8767-897fc40559ac@aklaver.com> <03EC7E36-EA7F-452A-B0A9-2F0FBB73E914@msqr.us> <00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox