Hi Augusto Piva ,
Thankyou for using Microsoft Q&A platform and thanks for posting your query here.
It sounds like you're encountering a common issue with PostgreSQL where duplicate key
Instead of ignore dup key, Use the ON CONFLICT
clause with DO NOTHING
or DO UPDATE
to handle conflicts:
INSERT INTO table_name (column1, column2)
VALUES (value1, value2)
ON CONFLICT (unique_column) DO NOTHING;
For more details, kindly check this documentation: https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT
For the existing duplicates, identify the duplicate value causing the error and clean up the data by removing or updating duplicates:
SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > 1;
DELETE FROM table_name
WHERE ctid NOT IN (
SELECT MIN(ctid)
FROM table_name
GROUP BY unique_column
);
Hope it helps. Kindly accept the answer by clicking on Accept answer
button . Thankyou