aio-libs / aio-libs/aiopg

How to handle table names in queries?

Đang mở
#751 0 bình luận 4 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
1.4k
Fork
170
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

`psycopg` has a [documentation section](https://www.psycopg.org/docs/sql.html#module-psycopg2.sql) 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.