views:

89

answers:

1

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])
+6  A: 
select([foo], foo.c.bar.in_([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.

nosklo
Thanks for the quick answer.A typo in your example, _in should be in_.
Mathias
@Mathias: thanks.
nosklo