本文介绍了python sqlalchemy标签用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用label方法作为别名,但是我不知道以后如何在查询中使用有标签的元素-类似于以下内容:
I know I can use the label method for alias, but I can't figure out how to use the labeled element later in the query - something like the following:
session.query(Foo.bar.label("foobar")).filter(foobar > 10).all()当然,这没有用,因为没有名为foobar的变量。
Of course, this doesn't work since there is no variable called foobar. How could this be accomplished?
(上面的简化示例只是为了易于理解...)
(The over simplified example was just for easy comprehension...)
推荐答案立即,我相信您可以将带有标签的列本身用作表达式:
Offhand, I believe you can use the labeled column itself as an expression:
foobar = Foo.bar.label("foobar") session.query(foobar).filter(foobar > 10).all()更多推荐
python sqlalchemy标签用法
发布评论