title: psycopg2.ProgrammingError: syntax error at or near "\"
body: <p>I have a python module which copy data from a table to a file.Im using postgresql as database server. COPY is the command is to be used to do the above action.</p>
  
  <p>However in a blog (<a href="http://grokbase.com/t/postgresql/pgsql-general/058tagtped/about-error-must-be-superuser-to-copy-to-or-from-a-file" rel="noreferrer">http://grokbase.com/t/postgresql/pgsql-general/058tagtped/about-error-must-be-superuser-to-copy-to-or-from-a-file</a>) it states that, You can use \copy in 'psql' on the client side, but you have to be a superuser to do COPY on the server side, for security reasons. So I used \copy command. When I try to execute the below method, it results in error as </p>
  
  <blockquote>
    <p>psycopg2.ProgrammingError: syntax error at or near "\" LINE 1: \copy</p>
  </blockquote>
  
  <p>I can't find why its throwing error. can someone help me out?</p>
  
  <pre><code>def process():
       query="\copy %s TO %s"%('test_table', 'test_file.txt')
  
       @env.with_transaction()
       def do_execute(db):
           cursor = db.cursor()
           cursor.execute(query)
  </code></pre>
  
  <blockquote>
    <p>do_execute is a database wrapper, which creates connection and
    executes the query.</p>
  </blockquote>