On Sep 17, 2010, at 7:50 AM, sajuptpm wrote:

> 
> DBSession.query(func.length(class_name.cpu_util),
> (DBSession.query(func.variance(class_name.util)).\
> 
> filter(class_name.entity_id==entity_id).filter(class_name.metric_type==metric_type).
> \
> 
> filter(class_name.cdate>=from_date).filter(class_name.cdate<=to_date).all()),
> \
>            func.avg(class_name.m_util)).\
> 
> filter(class_name.entity_id==entity_id).filter(class_name.metric_type==metric_type).
> \
> 
> filter(class_name.cdate>=from_date).filter(class_name.cdate<=to_date).all()

all() executes the SQL and returns a list, not a subquery.   You would need to 
remove the call to .all() from your subquery.

to label the subquery, session.query(...).subquery().label('foo').



> 
> 
> ERROR
> ======
>  File "/root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6-
> py2.4.egg/sqlalchemy/orm/scoping.py", line 123, in do
>    return getattr(self.registry(), name)(*args, **kwargs)
>  File "/root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6-
> py2.4.egg/sqlalchemy/orm/session.py", line 895, in query
>    return self._query_cls(entities, self, **kwargs)
>  File "/root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6-
> py2.4.egg/sqlalchemy/orm/query.py", line 92, in __init__
> 
>    self._set_entities(entities)
>  File "/root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6-
> py2.4.egg/sqlalchemy/orm/query.py", line 99, in _set_entities
>    entity_wrapper(self, ent)
>  File "/root/tg2env/lib/python2.4/site-packages/SQLAlchemy-0.5.6-
> py2.4.egg/sqlalchemy/orm/query.py", line 2099, in __init__
>    raise sa_exc.InvalidRequestError(
> InvalidRequestError: SQL expression, column, or mapped entity expected
> - got '[(0.0,)]'
> 
> 
> 
> 
> Here i am using a subquery to find variance. How give a name to
> subquery result column.
> (DBSession.query(func.variance(class_name.util)).\
> 
> filter(class_name.entity_id==entity_id).filter(class_name.metric_type==metric_type).
> \
> 
> filter(class_name.cdate>=from_date).filter(class_name.cdate<=to_date).all())
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to