Using Python and sqlalchemy:
How can I achieve the following MySQL statement with a WHERE ... IN clause using a tuple?
SELECT * FROM mytable WHERE (symbol, volume) IN (('ES', 238 ),('GB', 500 ),('OH', 800 ));
in sqlalchemy core (ie not the ORM version)
I looked in the documentation and generally on SO/google, this is nowhere to be found...
Assuming you use the declarative style (i.e. ORM classes). For your table there should be a orm class. I am assuming it as MyTable. Then the code will be like this:
keys = [
('ES', 238 ),('GB', 500 ),('OH', 800 )
]
select([
MyTable.url
]).select_from(
MyTable
).where(
tuple_(MyTable.symbol, MyTable.volume).in_(keys)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With