title: Can't create unique index in postgres, it says "key is duplicate" even when it's not
body: <p>I created a unique index for a table and got the following error:</p>
  
  <pre><code>SQL error: ERROR: could not create unique index "unique_product" DETAIL: Key (mastercode)=() is duplicated
  </code></pre>
  
  <p>So i run a query to check for duplicated records and really found some duplicates:</p>
  
  <pre><code>select * from product p where (select count(*) from product pp where pp.mastercode = p.mastercode) &gt; 1
  </code></pre>
  
  <p>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. </p>
  
  <p>Looks like it didn't update the indices after deleting the duplicates, or something like that. How can i solve this?</p>
  
  <p><strong>UPDATE</strong>
  Something i forgot to mention but may be important, i already have an index on the field <code>mastercode</code>, which is a default index (not unique). Don't know if this has something to do.</p>