【发布时间】:2015-03-31 23:36:59
【问题描述】:
您好 SQLAlchemy 专家,这里有一个棘手的问题:
我正在尝试编写解析为以下内容的查询:
SELECT * FROM MyTable where my_column LIKE ANY (array['a%', 'b%'])
使用 SQLAlchemy:
foo = ['a%', 'b%']
# this works, but is dirty and silly
DBSession().query(MyTable).filter("my_column LIKE ANY (array[" + ", ".join(["'" + f + "'" for f in token.tree_filters]) + "])")
# something like this should work (according to documentation), but doesn't (throws "AttributeError: Neither 'AnnotatedColumn' object nor 'Comparator' object has an attribute 'any'"
DBSession().query(MyTable).filter(MyTable.my_column.any(foo, operator=operators.like)
有什么解决办法吗?
【问题讨论】:
标签: python sqlalchemy any