MagicStack / MagicStack/asyncpg

Unable to use f-string in SqlAlchemy ORM

Đang mở
#781 1 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Python
Star
8.1k
Fork
468
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

  • asyncpg version: 0.23.0
  • PostgreSQL version: 12
  • Python version: 3.9.4
  • Platform: OSX
  • Do you use pgbouncer?: No
  • Did you install asyncpg with pip?: pipenv
  • If you built asyncpg locally, which version of Cython did you use?: N/A
  • Can the issue be reproduced under both asyncio and
    uvloop?
    : N/A

I'm trying to build a SQL statement with LIKE expression and a pattern but I'm getting an error.

Here is what I had in the code originally:

statement = select(Customer).options(sqlalchemy.orm.joinedload(Customer.transactions)).where(Customer.l_name.ilike(name))

and this worked great.

But if I want to use this statement with a % pattern like this:

statement = f'select(Customer).options(sqlalchemy.orm.joinedload(Customer.transactions)).where(Customer.l_name.ilike("%{name}%"))'

I get this error:

sqlalchemy.exc.ProgrammingError: (sqlalchemy.dialects.postgresql.asyncpg.ProgrammingError) <class 'asyncpg.exceptions.PostgresSyntaxError'>: syntax error at or near "("
[SQL: select(Customer).options(sqlalchemy.orm.joinedload(Customer.transactions)).where(Customer.l_name.ilike("%%turing%%"))]

It does substitute the variable with a parameter but for some reason it adds an extra pair of percent signs and crashes.
How can I solve this problem?

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

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Không có tệp, bài kiểm thử hoặc điểm vào nào của asyncpg được nêu tên. Bắt đầu với biểu thức SQLAlchemy và SQL được sinh ra đã cung cấp, sau đó xác minh xem hành vi có tái hiện trong asyncpg hay bắt nguồn từ việc xây dựng câu lệnh ORM dưới dạng chuỗi; xác nhận kết quả với các phiên bản PostgreSQL và asyncpg được liệt kê.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
postgresql, python
Lĩnh vực
databases
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
22/100

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.