[Python] Why composing a SQLAlchemy select doesn't work

Discussão em 'Python' iniciado por Stack, Maio 20, 2025.

  1. Stack

    Stack Membro Participativo

    Consider following snippet:

    stmt = db.select(Product).where(Product.id == 1)
    print(stmt)

    stmt = db.select(Product)
    stmt.where(Product.id == 1)
    print(stmt)


    i'd expect to have equal stmt, but instead i got:

    SELECT product.id, product.code, product."desc", product.unit, product.cost_price, product.sale_price
    FROM product
    WHERE product.id = :id_1

    SELECT product.id, product.code, product."desc", product.unit, product.cost_price, product.sale_price
    FROM product


    the last stmt doesn't include the where closure.

    Why this happens?

    Continue reading...

Compartilhe esta Página