l>>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 "", line 1, in
> ps
and getting this error :-
>>> cur.execute("""\set my_user table1""")
Traceback (most recent call last):
File "", line 1, in
psycopg2.ProgrammingError: syntax error at or near "\"
LINE 1: \set my_user table1
Can anyone please help me out here.
Thanks,
Vipul
--
https://mail.python.org/mailman/listinfo/python-list
Thanks for the replies. The param style is pyformat. I've tried
using the '%s' style with a set and get exactly the same error.
c.execute('SELECT * FROM %s LIMIT 1',('mytable',))
psycopg2.ProgrammingError: syntax error at or near "E'mytable'&q
"mytable"})
>
> It fails, giving the error message...
>
> Traceback (most recent call last):
> File "test.py", line 7, in
> c.execute('SELECT * FROM %(table_name)s LIMIT 1',
> {'table_name':"mytable"})
> psycopg2.ProgrammingE
MRAB wrote:
I think that you're confusing Python's string formatting with
SQL placeholders.
The "%(table_name)s" works only with Python's '%' operator.
You should use only the "%s" form (or possibly "?", I'm not
sure which!)
It varies depending on your DB driver. Check out the .paramstyle
error message...
Traceback (most recent call last):
File "test.py", line 7, in
c.execute('SELECT * FROM %(table_name)s LIMIT 1',
{'table_name':"mytable"})
psycopg2.ProgrammingError: syntax error at or near "E'mytable'&q
age...
Traceback (most recent call last):
File "test.py", line 7, in
c.execute('SELECT * FROM %(table_name)s LIMIT 1',
{'table_name':"mytable"})
psycopg2.ProgrammingError: syntax error at or near "E'mytable'"
LINE 1: SELECT * FROM