Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle table names in queries? #751

Open
cdvv7788 opened this issue Nov 24, 2020 · 0 comments
Open

How to handle table names in queries? #751

cdvv7788 opened this issue Nov 24, 2020 · 0 comments

Comments

@cdvv7788
Copy link

psycopg has a documentation section explaining why you cannot use %s for table names (quoting will cause syntax errors).

In aiopg examples, there is nothing that shows how this could be done.

I was able to run it by doing something like this:

from psycopg2 import sql
query = sql.SQL("select * from {}").format(sql.Identifier(table_name))
query = query.as_string(conn._connection._conn) # Use the wrapped psycopg connection

This works, but is there a less hacky way to achieve this? I could not find it in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant