Insert on conflict do update fails with duplicate rows - there are no duplicates - Mailing list pgsql-novice

From Pedro Moraes
Subject Insert on conflict do update fails with duplicate rows - there are no duplicates
Date
Msg-id CACqNvkPfEasOmKETeDTqm=vGOtR5yqAaMLL4kR_gmuZYPXfzWg@mail.gmail.com
Whole thread Raw
Responses Re: Insert on conflict do update fails with duplicate rows - there are no duplicates
List pgsql-novice

I managed to replicate the issue with the following data & tables attached download link.

I am trying to insert from bugtest.temp_on_conflict_test into bugtest.history, both tables have a primary key on history_id so there cannot be duplicates

The insert query also uses distinct on (history_id)

INSERT INTO bugtest.history (account_id,appo_id,account_name,resource_owner_name,resource_owner_id,resource_owner_user_id,resource_id,resource_type,preview,resource_date,history_id)
select distinct on (history_id) * from bugtest.temp_on_conflict_test limit 2
ON CONFLICT (history_id) DO UPDATE SET
account_id = excluded.account_id,
resource_owner_name = excluded.resource_owner_name,
resource_owner_user_id = excluded.resource_owner_user_id,
resource_owner_id = excluded.resource_owner_id,
preview = excluded.preview,
resource_date = excluded.resource_date,
account_name = excluded.account_name
RETURNING *

pgsql-novice by date:

Previous
From: Ken Dibble
Date:
Subject: Re: Command Line option misunderstanding
Next
From: Laurenz Albe
Date:
Subject: Re: Insert on conflict do update fails with duplicate rows - there are no duplicates