You are here

20 February 2017

To get custom columns from a query you can use the with_entities() method to restrict which columns you'd like to return in the result. Use label() method to give AS value to your query. To use functions, look up func the function generator. Documentation link:

Source code viewer
  1. result = db\
  2. .query(SomeModel)\
  3. .with_entities(
  4. SomeModel.column_1.label('c1'),
  5. SomeModel.column_2.label('c2')
  6. )
Programming Language: Python