On Mar 25, 2007, at 6:17 PM, Koen Bok wrote:


> stock_request = select(
>       [stock_request_join] + \
>       [stock_table.c.quantity.op('-')
> (func.sum(request_table.c.quantity)).label('unordered')] + \
>       [stock_table.c.quantity.op('-')
> (func.sum(request_table.c.allocation)).label('unallocated')],
>       group_by=[c for c in stock_request_join.c],
>       correlate=False).alias('stock_request')
>
> This generates the right SQL. But I can't get it to work with the
> original column names, then I get name ambigious errors.

dont know what a name ambiguous error is (usually thats thrown by  
postgres directly, meaning the SQL *is* wrong).

> When I do it
> with the joined names, the mapper tries to insert a request too when I
> want to create stock which makes kind of sense.
>
> When I remove [stock_request_join] and insert [c for c in
> stock_request_join.c] the JOIN syntax is being removed and it does a
> regular select against request and stock.
>
> Basically I want to end up with a regular Stock object with the
> aggregrate columns request_table.c.quantity and
> request_table.c.allocation. I have it working with a regular select,
> but if there is no request in te table linked to a stock it does not
> return that stock when doing a session.query(Stock).select(). Left
> outer joining request would do the trick.

select([stock_table, request_table.c.quantity,  
request_table.c.allocation], from_obj=[stock_table.outerjoin 
(request_table)]) ?





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