Skip to content

INSERT from SELECT UNION #3044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sqlalchemy-bot opened this issue May 8, 2014 · 4 comments
Closed

INSERT from SELECT UNION #3044

sqlalchemy-bot opened this issue May 8, 2014 · 4 comments
Labels
bug Something isn't working sql
Milestone

Comments

@sqlalchemy-bot
Copy link
Collaborator

Migrated issue, originally created by Michael Bayer (@zzzeek)

see if we don't need the subquery here:

from sqlalchemy import *
from sqlalchemy.sql import table, column

product = table('product', column('id'), column('other_id'))

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

patch:

index 61abe81..2b4320a 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -42,7 +42,7 @@ def _interpret_as_select(element):
     element = _interpret_as_from(element)
     if isinstance(element, Alias):
         element = element.original
-    if not isinstance(element, Select):
+    if not isinstance(element, SelectBase):
         element = element.select()
     return element
 

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

  • Fixed bug in INSERT..FROM SELECT construct where selecting from a
    UNION would wrap the union in an anonymous (e.g. unlabled) subquery.
    fixes INSERT from SELECT UNION #3044

482a67e

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

  • Fixed bug in INSERT..FROM SELECT construct where selecting from a
    UNION would wrap the union in an anonymous (e.g. unlabled) subquery.
    fixes INSERT from SELECT UNION #3044

076eef5

@sqlalchemy-bot
Copy link
Collaborator Author

Michael Bayer (@zzzeek) wrote:

  • Fixed bug in INSERT..FROM SELECT construct where selecting from a
    UNION would wrap the union in an anonymous (e.g. unlabled) subquery.
    fixes INSERT from SELECT UNION #3044

83b2e9e

@sqlalchemy-bot
Copy link
Collaborator Author

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

@sqlalchemy-bot sqlalchemy-bot added bug Something isn't working sql labels Nov 27, 2018
@sqlalchemy-bot sqlalchemy-bot added this to the 0.9.5 milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sql
Projects
None yet
Development

No branches or pull requests

1 participant