title: Suppress "duplicate key value violates unique constraint" errors
body: <p>I'm developing a Rails 3 app that uses Postgres as its database. I've got the table shown below:</p>
  
  <pre><code>             Table "public.test"
      Column     |  Type   | Modifiers
  ---------------+---------+-----------
   id            | integer | not null
   some_other_id | integer |
  Indexes:
      "test_pkey" PRIMARY KEY, btree (id)
      "some_other_id_key" UNIQUE CONSTRAINT, btree (some_other_id)
  </code></pre>
  
  <p>This has two columns:</p>
  
  <ul>
  <li>id, which is the primary key (automatically created by rails)</li>
  <li>some_other_id, which contains keys generated by another system. This id needs to be unique, so I've added a unique key constraint to the table. </li>
  </ul>
  
  <p>Now if I try to insert a row with a duplicate <code>some_other_id</code>, it fails (good) and I get the following output in my Postgres logs:</p>
  
  <blockquote>
  <pre><code>ERROR:  duplicate key value violates unique constraint "some_other_id_key"
  </code></pre>
  </blockquote>
  
  <p>The problem is that it's completely mainline for my app to try and add the same ID twice, and my logs are being spammed with this "ERROR" message, which causes various problems: files take a lot of disk space, diagnostics get lost in the noise, Postgres has to throw away diags to keep the log files within size limits, etc. </p>
  
  <p>Does anyone know how I can either:</p>
  
  <ul>
  <li>Suppress the log, either by suppressing all logs about this key, or perhaps by specifying something on the transaction that tries to do the <code>INSERT</code>.</li>
  <li>Use some other Postgres feature to spot the duplicate key and not try the <code>INSERT</code>. I've heard of rules and triggers but I can't get either to work  (though I'm no Postgres expert).</li>
  </ul>
  
  <p>Note that any solution needs to work with Rails, which does its inserts like this:</p>
  
  <pre><code>INSERT INTO test (some_other_id) VALUES (123) RETURNING id;
  </code></pre>