title: How does LIMIT interact with DELETE by primary key in Postgres? (Fix corrupt unique index)
body: <p>I've been handed a database that's stuck in a weird state. At some indeterminate time in the past, I ended up in a situation where I had duplicate rows in the same table with the same primary key:</p>
  
  <pre><code>=&gt; \d my_table
  Table "public.my_table"
         Column       |          Type           | Modifiers 
  --------------------+-------------------------+-----------
   id                 | bigint                  | not null
   some_data          | bigint                  | 
   a_string           | character varying(1024) | not null
  Indexes:
  "my_table_pkey" PRIMARY KEY, btree (id)
  
  =&gt; SELECT id, count(*) FROM my_table GROUP BY id HAVING count(*) &gt; 1 ORDER BY id;
  #50-some results, non-consecutive rows.
  </code></pre>
  
  <p>I have no idea how the database got into this state, but I want to be able to safely get out of it. If, for each duplicated primary key, if I execute a query of the form:</p>
  
  <pre><code>DELETE FROM my_table WHERE id = "a_duplicated_row" LIMIT 1;
  </code></pre>
  
  <p>Is it only going to delete <em>one</em> row from the table, or is it going to delete both rows with the given primary key?</p>