title: unique index on distinct combination
body: <p>I would like to ensure that a safe_id is only assigned to always the same user_id.
  However, the same user_id, safe_id combination is allowed multiple times</p>
  <p>ok:</p>
  <pre><code>user_id, safe_id, ...
  1, 1
  1, 2
  1, 3
  1, 2
  1, 2
  2, 5
  2, 6
  2, 6
  </code></pre>
  <p>not ok:</p>
  <pre><code>user_id, safe_id, ...
  1, 1
  1, 2
  1, 3
  1, 2
  1, 2
  2, 5
  2, 3  --&gt; this safe_id is assigned to two user_ids
  2, 6
  </code></pre>
  <p>This is a query that would give me the combinations that break this restriction:</p>
  <pre><code>SELECT safe_id, COUNT(DISTINCT user_id) FROM T GROUP BY safe_id HAVING COUNT(DISTINCT user_id) &gt; 1;
  </code></pre>
  <p>Is there some way to do this on the DB level? A normal unique index on user_id, safe_id is not possible because the combination is allowed multiple times.</p>