selecting literals fails with a union
q1 = session.query(cls1, literal("cls1")) q2 = session.query(cls2, literal("cls2")) Q = q1.union(q2)
result is two subqueries that select the different literals, but the outer query also selects from a literal (passed as a seperate param) equal to the literal from q1.
Comments (4)
-
Account Deleted -
repo owner there's a reason for that behavior (but I can't find the test for it, thought there was one). For a workaround:
q1 = sess.query(cls1, literal("cls1").label('labelname')) q2 = ... u = union(q1, q2) sess.query(SomeClass, u.c.labelname).select_from(u)
-
repo owner OK yeah it was just something that was never figured out before. Have an approach that is better in 3984cad7228fcc8fae9c3be93ecd86f6b08ed4b3, takes the extra step of re-stating the columns in terms of the new
union()
construct instead of reusing those of the generatingQuery
. this is against 0.6 since it is a behavioral change that can break some queries (such as if you queried literal_column("'x'") without a label). -
repo owner - removed milestone
Removing milestone: 0.6.0 (automated comment)
- Log in to comment
(in the (hopefully unlikely) case that this won't be fixed, a patch or suggested workaround would be greatly appreciated!)