python - SQLAlchemy - override orm.Query.count for a database without subselect -


i using sqlalchemy database doesn't support subselects. means wouldn't work (where calendar model inheriting declarative base):

 calendar.query.filter(uuid=uuid).count() 

i trying override count method this:

def count(self):     col = func.count(literal_column("'uuid'"))     return self.from_self(col).scalar() 

however, from_self bit still subselect. can't this:

session.query(sql.func.count(calendar.uuid)).scalar() 

because want filter information query. there way can filter arguments current query without doing subselect?

thanks~

from sqlalchemy documentation:

for fine grained control on specific columns count, skip usage of subquery or otherwise control of clause, or use other aggregate functions, use func expressions in conjunction query(), i.e.:

from sqlalchemy import func  # count user records, without # using subquery. session.query(func.count(user.id))  # return count of user "id" grouped # "name" session.query(func.count(user.id)).\         group_by(user.name)  sqlalchemy import distinct  # count distinct "name" values session.query(func.count(distinct(user.name))) 

source: sqlalchemy (sqlalchemy.orm.query.query.count)


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -