title: No unique or exclusion constraint matching the ON CONFLICT
body: <p>I'm getting the following error when doing the following type of insert:</p>
  
  <p>Query:</p>
  
  <pre><code>INSERT INTO accounts (type, person_id) VALUES ('PersonAccount', 1) ON
  CONFLICT (type, person_id) WHERE type = 'PersonAccount' DO UPDATE SET
  updated_at = EXCLUDED.updated_at RETURNING *
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>SQL execution failed (Reason: ERROR: there is no unique or exclusion
    constraint matching the ON CONFLICT specification)</p>
  </blockquote>
  
  <p>I also have an unique INDEX:</p>
  
  <pre><code>CREATE UNIQUE INDEX uniq_person_accounts ON accounts USING btree (type,
  person_id) WHERE ((type)::text = 'PersonAccount'::text);
  </code></pre>
  
  <p>The thing is that sometimes it works, but not every time. I <em>randomly</em> get
  that exception, which is really strange. It seems that it can't access that
  INDEX or it doesn't know it exists.</p>
  
  <p>Any suggestion?</p>
  
  <p>I'm using PostgreSQL 9.5.5.</p>
  
  <p>Example while executing the code that tries to find or create an account:</p>
  
  <pre><code>INSERT INTO accounts (type, person_id, created_at, updated_at) VALUES ('PersonAccount', 69559, '2017-02-03 12:09:27.259', '2017-02-03 12:09:27.259') ON CONFLICT (type, person_id) WHERE type = 'PersonAccount' DO UPDATE SET updated_at = EXCLUDED.updated_at RETURNING *
   SQL execution failed (Reason: ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification)
  </code></pre>
  
  <p>In this case, I'm sure that the account does not exist. Furthermore, it never outputs the error when the person has already an account. The problem is that, in some cases, it also works if there is no account yet. The query is exactly the same. </p>