On Nov 10, 2008, at 12:08 PM, John Hunter wrote:

>
> On Mon, Nov 10, 2008 at 10:05 AM, King Simon-NFHD78
> <[EMAIL PROTECTED]> wrote:
>
>> Actually, the section after that (Using Subqueries) probably does
>> something very close to what you want. What's the result of these  
>> lines:
>>
>> q1 = (session.query(Snapshot.strategy, Snapshot.symbol, sum_pnl)
>>     .group_by(Snapshot.strategy, Snapshot.symbol)
>>     .having(sum_pnl<-15000)).subquery()
>>
>> q2 = (session.query(Snapshot.strategy, func.count('*'))
>>     .join(q1, Snapshot.strategy = q1.c.strategy)
>>     .groupby(Snapshot.strategy))
>
>
> I assume you mean '=='? I get a foreign key error on the join::
>
>    sum_pnl = func.sum(Snapshot.pnl)
>
>    q1 = (session.query(Snapshot.strategy, Snapshot.symbol, sum_pnl)
>         .group_by(Snapshot.strategy, Snapshot.symbol)
>         .having(sum_pnl<-15000)).subquery()
>
>    q2 = (session.query(Snapshot.strategy, func.count('*'))
>         .join(q1, Snapshot.strategy==q1.c.strategy)
>         .groupby(Snapshot.strategy))
>
>      File "/home/titan/johnh/dev/lib/python2.4/site-packages/ 
> SQLAlchemy-0.5.0rc3dev_r5205-py2.4.egg/sqlalchemy/sql/util.py",
> line 109, in join_condition
>        raise exc.ArgumentError(
> ArgumentError: Can't find any foreign key relationships between
> 'snapshot' and '{ANON 157186924 anon}'
>
> Still playing with the aliases in the link you referred me to above
> but haven't gotten there yet...
>
you need an extra tuple on the join, query.join((q1, s.s==q1.c.s))

i think I might need to look into raising an error when the arguments  
aren't sent properly, im not sure why it doesn't do that already.



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