ok, I don't think we are on a same page.  So let me explain what I
want and maybe unconfused myself on what is a proper way to get data
out of database via sqlalchemy orm style.

"Query class should not be confused with the Select class, which
defines database SELECT operations at the SQL (non-ORM) level. Query
differs from Select in that it returns ORM-mapped objects and
interacts with an ORM session, whereas the Select construct interacts
directly with the database to return iterable result sets"

I need to return ORM-mapped object.

This is non-ORM object:
s=sqlalchemy.select([th.RECORD_NO,sqlalchemy.func.count(th.RECORD_NO).
label('RECORD_NO_COUNT')],sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080404')).
group_by(th.RECORD_NO)

s.execute().fetchall()

Above statements should result in query like: 'select a,count(a) from
x where b=5,c=6 group by a'

In order to get ORM object I need to use query. (That is what I get
from reading the sentence I quoted)

By not knowing how sqlalchemy works and just using my intuition I
would assume that I should be able to do something like this:
sess.query(th).select([th.RECORD_NO,sqlalchemy.func.count(th.RECORD_NO).label('RECORD_NO_COUNT')],
sqlalchemy.and_(th.APPLIED_TEST==1,th.CODING_DATE=='20080404'))
.group_by(th.RECORD_NO).all()

but obviously the above does not work. I guess what I am confused is
how to use non-ORM syntax (its easy to follow) in an ORM way?




What you emailed below is making a join if I read it correctly, and I
don't think that is what I want.
>  sess.query(th).select_from(th_table.join(s,
>  th.RECORD_NO==s.c.RECORD_NO)).add_column(s.c.count).all()
>


Lucas

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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