[Sqlalchemy-tickets] Issue #2974: Union queries fail if there are literal unlabeled columns (zzzeek
Brought to you by:
zzzeek
|
From: yajo <iss...@bi...> - 2014-02-26 11:46:50
|
New issue 2974: Union queries fail if there are literal unlabeled columns https://bitbucket.org/zzzeek/sqlalchemy/issue/2974/union-queries-fail-if-there-are-literal yajo: See this union query: ``` #!python queries = list() queries.append(sql.select( columns=[ sql.expression.literal("column_1").label("label_1"), sql.expression.literal("column_2").label("label_2"), ], bind=conn.engine )) queries.append(sql.select( columns=[ sql.expression.literal("column_1"), sql.expression.literal("column_2"), ], bind=conn.engine )) one = sql.expression.union(*queries) ``` It fails with this exception: ``` sqlalchemy.exc.ArgumentError: All selectables passed to CompoundSelect must have identical numbers of columns; select #1 has 2 columns, select #2 has 1 ``` But both have 2 columns, it's just that the 2nd one is not labeled (because it is not needed in union queries, at least with MySQL). **Workaround:** labeling all columns in 2nd query. Notice that *real* columns, wich automatically seem to get a name, don't expose this weird behavior. |