pypika
pypika copied to clipboard
cannot union all when use 'Star' operation
If I have two table t1 and t2, the following code will throw an error
t1 = Table('t1')
t2 = Table('t2')
qq1 = Query.from_(t1).select(t1.a, t2.b)
q1 = Query.from_(q1).select(q1.star)
q2 = Query.from_(t2).select(t2.a, t2.b)
q = q1.union_all(q2)
q.get_sql()
This will throw error message "Queries must have an equal number of select statements in a set operation"
The reason I think is because when build sql, pypika checks len(q1._selects) == len(q2._selects). However, q1.star returns the length of 1, while it should contain two columns, which is the same length of q2._selects.
I am also having this issue. My target understands if I union a select * with a select a, b that this is a valid union.