yes the tuple construct provides this:
https://docs.sqlalchemy.org/en/13/core/sqlelement.html?highlight=tuple#sqlalchemy.sql.expression.tuple_
>>> from sqlalchemy import select, column, tuple_
>>> stmt = select([column('q')]).where(tuple_(column('x'), column('y')) ==
>>> tuple_(3, 4))
>>> print(stmt)
SELECT q
WHERE (x, y) = (:param_1, :param_2)
however, tuples are not supported on all backends and it's safer to use AND:
>>> from sqlalchemy import and_
>>> stmt = select([column('q')]).where(and_(column('x') == 3, column('y') == 4))
>>> print(stmt)
SELECT q
WHERE x = :x_1 AND y = :y_1
>From a Python perspective, there's no real reason to use one or the other, as
>either one can be generated programmatically.
the tuple_ construct is provided mostly to support IN expressions against
composite values, for equality it's not strictly necessary.
On Fri, Oct 9, 2020, at 8:51 AM, Massimiliano della Rovere wrote:
> Greetings,
> is it possible using sqlalchemy core to obtain the following code:
>
> [...]
> WHERE (column1, column2) = (value1, value2)
>
> this is useful to use multi columnar indexes having column1 and column2 in
> the two leftmost position and in later position columns that I put in the
> SELECT section.
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/CADKhPGRMO_CeHhFQiQXfHz-CWn76zDRXJrUp%2BFFzUv4VVchAOQ%40mail.gmail.com
>
> <https://groups.google.com/d/msgid/sqlalchemy/CADKhPGRMO_CeHhFQiQXfHz-CWn76zDRXJrUp%2BFFzUv4VVchAOQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/8455b948-e403-48bc-9851-572db0c5589f%40www.fastmail.com.