title: Add Check Constraint not working SQL
body: <p>I need to add a constraint to a table such that column ab is always greater than column h. I have tried</p>
  
  <pre><code>ALTER TABLE batting
  ADD constraint possibleHits check (ab&gt;h);
  </code></pre>
  
  <p>But that returns </p>
  
  <pre><code>ERROR:  check constraint "possiblehits" is violated by some row
  
  ********** Error **********
  
  ERROR: check constraint "possiblehits" is violated by some row
  SQL state: 23514
  </code></pre>
  
  <p>as an error.</p>
  
  <p>I have run </p>
  
  <pre><code>select * from batting where ab&lt;h
  </code></pre>
  
  <p>and it returns no rows.</p>
  
  <p>Any ideas on what i'm doing wrong? or is there a way to do something like add </p>
  
  <pre><code>NOT VALID
  </code></pre>
  
  <p>to the statement so that it will not enforce the constraint on existing rows?
  I know that that works in mysql but in postgres it only works on keys.</p>
  
  <p>EDIT:</p>
  
  <p>So as was pointed out there are instances where ab = h however is there a way to exclude existing rows from the constraint?</p>