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']

q1 = session.query(A.data.label('somedata'),
literal_column('\'A\'').label('source'))
q2 = session.query(B.data.label('somedata'),
literal_column('\'B\'').label('source'))
qry = q1.union(q2)
generates the SQL
    SELECT anon_1.somestuff AS somestuff, 'A' AS source
    FROM (SELECT a.data AS somestuff, 'A' AS source
    FROM a UNION SELECT b.data AS somestuff, 'B' AS source
    FROM b) AS anon_1

The correct code would be
    SELECT anon_1.somestuff AS somestuff, anon_1.source AS source
      etc.



-- 
Mike Conley

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