I created a unique index for a table and got the following error:
SQL error: ERROR: could not create unique index "unique_product" DETAIL: Key (mastercode)=() is duplicated
So i run a query to check for duplicated records and really found some duplicates:
select * from product p where (select count(*) from product pp where pp.mastercode = p.mastercode) > 1
But even after deleting them i could not create the index, it shows the same error and the query to check for duplicates shows nothing.
Looks like it didn't update the indices after deleting the duplicates, or something like that. How can i solve this?
UPDATE
Something i forgot to mention but may be important, i already have an index on the field mastercode
, which is a default index (not unique). Don't know if this has something to do.
A unique index never has duplicate values.
You can prevent duplicate values in a field in an Access table by creating a unique index. A unique index is an index that requires that each value of the indexed field is unique.
PostgreSQL automatically creates a unique index when a unique constraint or primary key is defined for a table. The index covers the columns that make up the primary key or unique constraint (a multicolumn index, if appropriate), and is the mechanism that enforces the constraint.
To change the tablespace of an index, you must own the index and have CREATE privilege on the new tablespace. All indexes in the current database in a tablespace can be moved by using the ALL IN TABLESPACE form, which will lock all indexes to be moved and then move each one.
Check the results from this query:
SELECT mastercode, count(*)
FROM product
GROUP BY mastercode
HAVING count(*) > 1; -- not unique
I believe you have an instance of a null mastercode, and are trying to insert another null mastercode.
Try select * from product where mastercode is null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With