I am connected to postgresql with sqlalchemy. When I try this code:
e = create_engine('')
r = e.execute("select ?", 5)
it gives me:
sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at end of input
Corresponding to http://www.sqlalchemy.org/docs/core/connections.html?highlight=engine#sqlalchemy.engine.base.Connection.execute there are different types of paramstyles…
After deeper research, i found out that default paramstyle for postgresql Dialect is “pyformat”.
Can somebody show me how to use this pyformat on some example?
I would just like to use placeholders or named placeholders for forming up the sql statement.
I tried:
e.execute("select %s, %s;", "test", "test2")
But this is not working either.
Thank you
edit:
of course, i am passing valid connection string to create_engine method 🙂
The documentation you link to, directly links to PEP 249, which shows you the different styles.
About pyformat it says:
So that’s what you need to use.
By Googling on “DBAPI pyformat” the second link is the link to the psycopg2 documentation. After mentioning that it uses pyformat there is a “See Also” linking to a page with loads of examples.
Examples of how to use it are in your original link:
You can also use this syntax:
Which is nicer.