Skip to content
Advertisement

Duplicate value in a postgresql table

I’m trying to modify a table inside my PostgreSQL database, but it says there is duplicate! what is the best way to find a duplicate value inside a table? kinda a select query?

Advertisement

Answer

If you try to change a value in a column that is part of the PRIMARY KEY or has a UNIQUE constraint and get this error there, then you should be able to find the conflicting row by

SELECT *
FROM your_table
WHERE conflicting_column = conflicting_value;

If conflicting_value is a character type, put it in single quotes (').

EDIT: To find out which columns are affected by the constraint, check this post.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement