views:

394

answers:

1

How do I translate something like this into SQLAlchemy?

SELECT (a * b) - (x + y) / z AS result
FROM table
ORDER BY result
+2  A: 

Just pass the label in as a string argument to order_by:

result_exp = sqlalchemy.sql.expression.label('result',
   ((test2_table.c.a * test2_table.c.b)
    - (test2_table.c.x + test2_table.c.y)
    / test2_table.c.z))
select([result_exp], from_obj=[test2_table], order_by="result")
Charles Duffy