title: SQL Complex number constraint
body: <p>Hello i am using PostegreSQL and i want to constrain a certain number(tax ID number) to obey the following rules:</p>
  
  <ul>
  <li>9 Digits</li>
  <li>The last digit (z) is calculated according to:</li>
  </ul>
  
  <p>x = 8th * 2 + 7th * 3 + 6th * 4 + 5th * 5 + 4th * 6 + 3rd * 7 + 2nd * 8 + 1st + 9</p>
  
  <pre><code>y = x % 11  
  if (y == 0 || x == 1) z = 0;
  else z = 11 - y
  </code></pre>
  
  <p>Is this possible in sql?</p>