【问题标题】:How do I put a SQLAlchemy label on the result of an arithmetic expression?如何在算术表达式的结果上放置 SQLAlchemy 标签?
【发布时间】:2010-09-27 01:43:21
【问题描述】:

如何将这样的内容翻译成 SQLAlchemy?

select x - y as difference...

我知道该怎么做:

x.label('foo')

...但我不确定在下面将“.label()”方法调用放在哪里:

select ([table.c.x - table.c.y], ...

【问题讨论】:

    标签: python sqlalchemy


    【解决方案1】:

    ColumnElement 方法只是一个助手; label()可以通过以下方式使用:

    select([sql.expression.label('foo', table.c.x - table.c.y), ...])
    

    【讨论】:

      猜你喜欢
      • 2020-02-10
      • 2010-09-27
      • 1970-01-01
      • 2016-04-14
      • 2011-01-25
      • 2012-02-26
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多