title: Python psycopg2 copy_from() to load data throws error for null integer values: DataError: invalid input syntax for integer: ""
body: <p>I am trying to load data from a StringIO object of python into a Postgres database table using psycopg2's copy_from() method.</p>
  
  <p>My copy_from fails on the first record itself specifically for a particular (nullable) integer column which has null value ('' without quotes). I have also tried using Python's None keyword instead of '' for NULL values.
  It throws me the following error:
  <strong>DataError: invalid input syntax for integer: ""
  CONTEXT:  COPY , line 1, column : ""</strong></p>
  
  <p>The code looks something like this:</p>
  
  <pre><code>table_data = StringIO.StringIO()
  # Populate the table_data variable with rows delimited by \n and columns delimited by \t
  cursor = db_connection.cursor()
  cursor.copy_from(table_data, &lt;table_name&gt;)
  </code></pre>
  
  <p>This column  is a smallint column.</p>