How to make ORDER BY an arithmetic expression in SQLAlchemy?

How to translate something like this in SQLAlchemy?

SELECT (a * b) - (x + y) / z AS result FROM table ORDER BY result 
+3
source share
1 answer

Just pass the label as a string argument to order_by :

 result_exp = sqlalchemy.sql.expression.label('result', ((test2_table.ca * test2_table.cb) - (test2_table.cx + test2_table.cy) / test2_table.cz)) select([result_exp], from_obj=[test2_table], order_by="result") 
+3
source

All Articles