title: How do I use psql "\copy" in Python?
body: <p>I'm trying to import a csv-file into a psql database. After reading about the difference between <code>COPY</code> and <code>\copy</code> I get this error when executing my script.</p>
  
  <p>Here's my code cutting:</p>
  
  <pre><code>try:
  
     csv_data = os.path.realpath('test.csv')
  
     con = psycopg2.connect(database = 'db01', user = 'postgres')
     cur = con.cursor()
  
     cur.execute("\copy stamm_data from '%s' DELIMITER ';' csv header" % csv_data)
  
     con.commit()
  </code></pre>
  
  <p>And here's the error:</p>
  
  <pre><code>Error: syntax error at or near "\"
  LINE 1: \copy stamm_data from '/home/jw/dev/test.csv' delimiter ';' ...
      ^
  </code></pre>
  
  <p>When using <code>COPY</code> I get:</p>
  
  <pre><code>Error: could not open file "/home/jw/dev/test.csv" for reading: Permission denied
  </code></pre>
  
  <p>Though the psql user 'postgres' is a superuser and the ubuntu user to run the script has reading permissions on the test.csv file.</p>
  
  <p>Any ideas? </p>