1. Michael Bayer
  2. sqlalchemy
  3. Issues

Issues

Issue #3044 resolved

INSERT from SELECT UNION

Michael Bayer
repo owner created an issue

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

Comments (3)

  1. Log in to comment