Is it possible to express a query like the one below in the “SQL Expression Language” used in SQLAlchemy?
SELECT * FROM foo WHERE foo.bar IN (1,2,3)
I want to avoid writing the WHERE-clause in plain text. Is there a way to express this similar to my examples below or in any way that doesn’t use plain text?
select([foo], in(foo.c.bar, [1, 2, 3]))
select([foo]).in(foo.c.bar, [1, 2, 3])
You can use the
.in_()method with Columns or with Instrumented attributes. Both work.It is mentioned here on SQLAlchemy’s first tutorial.