Using sqlalchemy to query using multiple columns where in section

I want to execute this query using sqlalchemy.

SELECT name, age, favorite_color, favorite_food FROM kindergarten_classroom WHERE (favorite_color, favorite_food) IN (('lavender','lentil soup'),('black','carrot juice')); 

I want only children who like (lavender and lentil soup) OR (black and carrot juice). Also, it will probably be a huge list of favorite colors and products (probably> 10K), so I want to do this in large batches.

This is similar, but not everything works out for me: Sqlalchemy in the section

+5
source share
1 answer

Do you want tuple_ construct:

 session.query(...).filter( tuple_(favorite_color, favorite_food).in_( [('lavender', 'lentil soup'), ('black', 'carrot juice')] ) ) 
+10
source

Source: https://habr.com/ru/post/1200891/


All Articles