简体   繁体   中英

How do I put a SQLAlchemy label on the result of an arithmetic expression?

How do I translate something like this into SQLAlchemy?

select x - y as difference...

I know how to do:

x.label('foo')

...but I'm not sure where to put the ".label()" method call below:

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

The ColumnElement method is just a helper; label() can be used following way:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM