title: PostgreSQL: COPY FROM SQL to specific columns
body: <p>I have been trying to figure out how to format a <code>COPY FROM</code> SQL statement for most of the morning and I need help.</p>
  
  <p>I am trying to import data from an ASCII text file to a table in my Postgres database. I am thinking it does not like how I am specifying the input ASCII file. I have tried both of the file paths with no luck:</p>
  
  <pre><code>file = os.path.normpath(os.path.join('c:\\','Users','dan','Desktop','New_Folder','Sept_2014','R01761','R01761_tex.asc'))
  file = r'C:\Users\dan\Desktop\New_folder\Sept_2014\R01761\R01761_tex.asc'
  </code></pre>
  
  <p>Here is my script I am using to access my database:</p>
  
  <pre><code>import psycopg2
  
  try:
      conn = psycopg2.connect("dbname='reach_4a' user='root' host='localhost' port='9000' password='myPassword'")
      tblname = "sept_2014""
      file = r"C:\Users\dan\Desktop\New_folder\Sept_2014\R01761\R01761_tex.asc"
      #file = os.path.normpath(os.path.join('c:\\','Users','dan','Desktop','New_Folder','Sept_2014','R01761','R01761_tex.asc'))
      cur = conn.cursor()
      sql = "COPY %s (easting,northing,texture) FROM %s DELIMITERS ' ';" % (tblname,file) 
      cur.execute(sql)
      conn.commit()
  except:
      print "I am unable to connect to the database"
  
  #Close Database
  try:
      conn.close()
      print 'Database connection destroyed'
  except:
      print "I cant close the database"
  </code></pre>
  
  <p>When I step through my script in a python console, I get the following error when i try and run the <code>cur.execute(sql)</code> line:</p>
  
  <pre><code>---------------------------------------------------------------------------
  ProgrammingError                          Traceback (most recent call last)
  &lt;ipython-input-34-c26e11f8fb81&gt; in &lt;module&gt;()
  ----&gt; 1 cur.execute(sql)
  
  ProgrammingError: syntax error at or near "c"
  LINE 1: COPY sept_2014 (easting,northing,texture) FROM c:\Users\dan\...
                                                         ^
  </code></pre>
  
  <p>Am I properly substituting my strings to my SQL statement?</p>