public inbox for [email protected]
help / color / mirror / Atom feedFrom: Pedro Moraes <[email protected]>
To: [email protected]
Subject: Insert on conflict do update fails with duplicate rows - there are no duplicates
Date: Mon, 27 Jan 2025 10:18:29 -0300
Message-ID: <CACqNvkPfEasOmKETeDTqm=vGOtR5yqAaMLL4kR_gmuZYPXfzWg@mail.gmail.com> (raw)
In-Reply-To: <CACqNvkOBzq8_z2+oygTd85-7U54mbWry8tfQLYU=MBMDTNRw1w@mail.gmail.com>
References: <CACqNvkOBzq8_z2+oygTd85-7U54mbWry8tfQLYU=MBMDTNRw1w@mail.gmail.com>
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 *
Reproducible dump:
https://limewire.com/d/2d598eff-f7c9-47d2-80d6-7e522ee1688c#ru2TRVilIqQdqmEjr2-_H4z67PHYe2JZAshDErA8...
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Insert on conflict do update fails with duplicate rows - there are no duplicates
In-Reply-To: <CACqNvkPfEasOmKETeDTqm=vGOtR5yqAaMLL4kR_gmuZYPXfzWg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox