title: MySQL: DECLARE CONTINUE HANDLER to continue on errors, printing a warning
body: <p>I am reviewing / redesigning / refactoring a database and want to create a new database that stores pretty much the same data in a smarter fashion. One of the problems in the 'legacy' database is that it does not make proper use of keys and indices, so there is duplicate entries where there should be none.</p>
  
  <p>I have written a python script that reads data from the legacy database and generates a SQL script which in turn inserts these values from the legacy database into the new database using a lot of very similar SQL INSERT statements. The SQL script stops every time it encounters a duplicate entry with an error message</p>
  
  <blockquote>
    <p>ERROR 1062 (23000) at line 3086: Duplicate entry '56.450000000--3.366670000-121' for key 'lat_lon_height'</p>
  </blockquote>
  
  <p>which AFAICT is exactly what it should do. However, for the moment, I just want the script to keep going, not insert the duplicate entries, but print a warning about them. I tried installing a continue handler at the beginning of the script in several ways following <a href="http://dev.mysql.com/doc/refman/5.0/en/declare-handler.html" rel="nofollow">the MySQL docs</a> and <a href="http://www.devshed.com/c/a/MySQL/Error-Handling-Examples/" rel="nofollow">some other online resources</a>, but all of them just create a syntax error:</p>
  
  <pre><code>DECLARE CONTINUE HANDLER FOR 1062 
  SELECT 'Duplicate key in unique index';
  </code></pre>
  
  <p>or</p>
  
  <pre><code>DECLARE CONTINUE HANDLER FOR SQLSTATE '23000'
  SELECT 'Duplicate key in unique index';
  </code></pre>
  
  <p>or</p>
  
  <pre><code>DECLARE CONTINUE HANDLER FOR SQLSTATE '23000'
  BEGIN
  SELECT 'Duplicate key in unique index';
  END;
  </code></pre>
  
  <p>What am I doing wrong ?</p>