python sqlalchemy标签用法 [英] python sqlalchemy label usage

查看:101
本文介绍了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标签用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆