Mike Conley wrote:
> Either of these works for the individual queries, but when combined in the
> union() or union_all() the result is still that the literal from the first
> query is used on all result rows
>
> q1 = session.query(A.data.label('somedata'), literal('A').label('source'))
> q2 = session.query(B.data.label('somedata'), literal('B').label('source'))
> qry = q1.union(q2)
> generates the SQL
>     SELECT anon_1.somestuff AS somestuff, ? AS source
>     FROM (SELECT a.data AS somestuff, ? AS source
>     FROM a UNION ALL SELECT b.data AS somestuff, ? AS source
>     FROM b) AS anon_1
> with bind parameters
>     ['A', 'A', 'B']

OK this is more of a select_from() use case.  I would try qry =
q1.union(q2).subquery(); Query(qry.foo, qry.bar).

query.union() is a little new so I'm not entirely convinced we have the
full flexibility of select() constructs here (which of course would be the
fallback).

--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to