Database-Independent MAX() Function in SQLAlchemy

时光总嘲笑我的痴心妄想 提交于 2019-12-12 14:24:12

问题


I'd like to calculate a MAX() value for a column. What's the proper way to do this in sqlalchemy while preserving database independence?


回答1:


You can find aggregate functions in:

from sqlalchemy import func 
func.avg(...) 
func.sum(...) 
func.max(...) 

In 0.5 you can use an ORM query like a select:

session.query(func.max(Table.column)) 


来源:https://stackoverflow.com/questions/2358634/database-independent-max-function-in-sqlalchemy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!