Wow, it worked - chapeau!

Thanks for the super-fast response time and the workaround...


On Friday, May 9, 2014 12:43:18 PM UTC+10, Michael Bayer wrote:
>
> OK well 
> https://bitbucket.org/zzzeek/sqlalchemy/issue/3044/insert-from-select-unionhas
>  a patch, that’s what we’ll be doing.
>
> a workaround might be to monkeypatch select() for now:
>
> sel = select(
>     [b_id, product.c.id],
> ).union(
>     select([b_id, s_id])
> )
> sel.select = lambda : sel
>
>
>
>
>
> On May 8, 2014, at 6:27 PM, gbr <[email protected] <javascript:>> 
> wrote:
>
> So what can I do? I'm using postgres 9.3
>
> The error message I get is:
>
> ProgrammingError: (ProgrammingError) subquery in FROM must have an alias
>> LINE 2: FROM (SELECT 2, product_id
>>              ^
>> HINT:  For example, FROM (SELECT ...) [AS] foo.
>>
>
> Adding `sel = sel.alias()` doesn't do anything (same error message). 
>
>
> On Friday, May 9, 2014 5:28:32 AM UTC+10, Michael Bayer wrote:
>>
>> 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 <[email protected]> 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 [email protected].
>> To post to this group, send email to [email protected].
>> 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 [email protected] <javascript:>.
> To post to this group, send email to [email protected]<javascript:>
> .
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to