title: PostgreSQL constraint using prefixes
body: <p>Let's say I have the following PostgreSQL table:</p>
  
  <pre><code>id | key
  ---+--------
  1  | 'a.b.c'
  </code></pre>
  
  <p>I need to prevent inserting records with a key that is a prefix of another key. For example, I should be able to insert:</p>
  
  <ul>
  <li><code>'a.b.b'</code></li>
  </ul>
  
  <p>But the following keys should not be accepted:</p>
  
  <ul>
  <li><code>'a.b'</code></li>
  <li><code>'a.b.c'</code></li>
  <li><code>'a.b.c.d'</code></li>
  </ul>
  
  <p>Is there a way to achieve this - either by a constraint or by a locking mechanism (check the existance before inserting)?</p>