On Apr 11, 2008, at 2:51 PM, Lukasz Szybalski wrote:

>
> 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)

 From the above, what ORM object would you like ?  the one which has  
"a" as one of its columns ?  if so, the recipe I gave you is the  
correct approach.

> 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()
>>
>


if you want to select a full row from the table, including its primary  
key, and you'd like that row to correspond to a particular aggregate  
query which needs to GROUP BY only part of the columns which does not  
include the primary key column, you must use a join or subquery to  
create the aggregate.

To illustrate, this is the query you think you want:

        select *, count(a) from table group by a

Why "*" ?  because you say that you want "ORM objects".   The ORM  
object represents the *full* row, including the primary key, of the  
table.

but again, that query is invalid SQL.    Most SQL-compliant databases  
will raise an error.   Another article explaining this:  
http://weblogs.sqlteam.com/jeffs/jeffs/archive/2007/07/20/60261.aspx 
  .

Therefore, the join or subquery is necessary if you wish to GROUP BY  
only particular columns.


--~--~---------~--~----~------------~-------~--~----~
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