python - psycopg2.ProgrammingError: syntax error at or near "\" -


i have python module copy data table file.im using postgresql database server. copy command used above action.

however in blog (http://grokbase.com/t/postgresql/pgsql-general/058tagtped/about-error-must-be-superuser-to-copy-to-or-from-a-file) states that, can use \copy in 'psql' on client side, have superuser copy on server side, security reasons. used \copy command. when try execute below method, results in error

psycopg2.programmingerror: syntax error @ or near "\" line 1: \copy

i can't find why throwing error. can me out?

def process():      query="\copy %s %s"%('test_table', 'test_file.txt')       @env.with_transaction()      def do_execute(db):          cursor = db.cursor()          cursor.execute(query) 

do_execute database wrapper, creates connection , executes query.

\ escape in python strings, string contains escape \c. \c invalid escape in python, , python leaves invalid escapes unchanged, "\copy" \copy. (thus @tiziano's answer misleading).

>>> print "\c" \c 

the real problem \copy psql command, not server side postgresql command. can't use client other psql. must instead use the psycopg2 support copy via client driver.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -