title: Python, Postgresql trouble copying from csv
body: <p>I am doing this all as a test. I want to take a csv file that has headers and copy the values into a postgresql database table. The tables columns are named the same as the headers in csv file case-sensitive. table has two columns "pkey", "m". the csv just has the "m" for header. pkey is just the primary key setup to auto increment. As a test i just want to copy the "m" column in the csv file the table.</p>
  
  <pre><code>import csv
  import psycopg2
  
  
  database = psycopg2.connect ( database = "testing", user="**", 
  password="**", host="**", port="**")
  
  ocsvf = open("sample.csv")
  
  def merger(conn, table_name, file_object):
      cursor = conn.cursor()
      cursor.copy_from(file_object, table_name, sep=',', columns=('mls'))
      conn.commit()
      cursor.close()
  
  try:
      merger(database, 'tests', ocsvf)
  finally:
      database.close()
  </code></pre>
  
  <p>when i try to run the code i get this as a error</p>
  
  <pre><code>Traceback (most recent call last):
    File "csvtest.py", line 26, in &lt;module&gt;
  merger(database, 'tests', ocsvf)
    File "csvtest.py", line 21, in merger
  cursor.copy_from(file_object, table_name, sep=',', columns=('m'))
    psycopg2.ProgrammingError: column "m" of relation "tests" does not exist
  </code></pre>
  
  <p>I am sure its something simple that i just keep over looking but i have also googled this and the one thing i found was someone said it might be the primary key is setup right but i tested it and the primary keys works fine when i do manual input from pgadmin. any help would be great thanks</p>