pypika icon indicating copy to clipboard operation
pypika copied to clipboard

cannot union all when use 'Star' operation

Open Yifei-Xiao opened this issue 4 years ago • 1 comments

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.

Yifei-Xiao avatar Jun 22 '21 03:06 Yifei-Xiao

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.

micah-williamson avatar Dec 02 '21 18:12 micah-williamson