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

maheshyadav1771 at gmail.com maheshyadav1771 at gmail.com
Fri Oct 27 11:35:20 EDT 2017


Hello,

I am using 'psycopg2' library to access my PostgreSQL database from a python. I want to pass a variable input in psql query something like this :- 

psql>>\set my_user table1
psql>>select * from :my_user limit 10;

So I am just running these sql commands and getting this error :-

>>> cur.execute("""\set my_user table1""")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
psycopg2.ProgrammingError: syntax error at or near "\"
LINE 1: \set my_user table1


Can anyone please help me out here.

Thanks,
Vipul



More information about the Python-list mailing list