Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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], ...
like image 878
mike Avatar asked Jan 24 '23 23:01

mike


1 Answers

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

select([sql.expression.label('foo', table.c.x - table.c.y), ...])
like image 78
Charles Duffy Avatar answered Jan 28 '23 15:01

Charles Duffy