this can't be avoided right now as the insert from select feature checks the 
incoming object as a "Select", which a "UNION" is not; it then calls select() 
on that union.

a lot of databases have trouble with a raw UNION like that, we can loosen this 
restriction to apply to union-orinented selects as well but it's not clear if 
some backends might have problems with it.

On May 8, 2014, at 4:28 AM, gbr <doubl...@directbox.com> wrote:

> I don't quite understand why SQLA generates this query. For some reason it 
> wraps the union part into a separate select. How can I avoid this?
> 
> b_id = 2
> s_id = 3
> id = product.c.id
> sel = select(
>     [b_id, product.c.id],
> ).union(
>     select([b_id, s_id])
> )
> 
> ins = insert(product).from_select([
>     product.c.id, product.c.other_id
>     ],
>     sel
> )
> print ins
> # produces:
> # INSERT INTO product (id, other_id) SELECT 2, id 
> # FROM (SELECT 2, product.id AS id 
> # FROM product UNION SELECT 2, 3)
> 
> # I would expect:
> # INSERT INTO product (id, other_id) FROM 
> #   SELECT 2, product.id AS id FROM product 
> #   UNION 
> #   SELECT 2, 3
> 
> Where is the additional `SELECT 2, id` coming from?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to