1

I know it's possible to label an arbitrary column in a query:

session.query(Person.name.label("name"))

It isn't possible to do this:

session.query((Person.age + Person.wealth).label("sum"))

How would I go about labeling an addition of different columns?

danihodovic
  • 1,151
  • 3
  • 18
  • 28

1 Answers1

0

Seems like it can be solved with literal_column which takes arbitrary column names as text and returns SQLAlchemy objects. session.query(literal_column("age + wealth").label("lbl"))

Edit: Using

session.query((Person.age + Person.wealth).label("lbl"))

works. My bad

danihodovic
  • 1,151
  • 3
  • 18
  • 28