summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/selectable.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-12-16 16:38:06 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2019-12-16 16:38:06 -0500
commite7c78be2e737591d637b6acde6117893fd29dfe0 (patch)
tree11abdbd136f0e9cfcf8959a7c41d2d4d0f27772c /lib/sqlalchemy/sql/selectable.py
parent835bdabd05c83e3add3e876a861aa74105d34397 (diff)
downloadsqlalchemy-e7c78be2e737591d637b6acde6117893fd29dfe0.tar.gz
Do the CompoundSelect check for number of columns in the compile phase
Starting to go forward with the general idea of moving more of Core / ORM construction into the compile phase. Bigger initiatives like the refactor of Query will follow onto this. Change-Id: I0f364d3182e21e32ed85ef34cfd11fd9d11cf653
Diffstat (limited to 'lib/sqlalchemy/sql/selectable.py')
-rw-r--r--lib/sqlalchemy/sql/selectable.py31
1 files changed, 6 insertions, 25 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index 5f609f8fd..bece0b3c5 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -2782,31 +2782,12 @@ class CompoundSelect(GenerativeSelect):
def __init__(self, keyword, *selects, **kwargs):
self._auto_correlate = kwargs.pop("correlate", False)
self.keyword = keyword
- self.selects = []
-
- numcols = None
-
- # some DBs do not like ORDER BY in the inner queries of a UNION, etc.
- for n, s in enumerate(selects):
- s = coercions.expect(roles.CompoundElementRole, s)
-
- if not numcols:
- numcols = len(s.selected_columns)
- elif len(s.selected_columns) != numcols:
- raise exc.ArgumentError(
- "All selectables passed to "
- "CompoundSelect must have identical numbers of "
- "columns; select #%d has %d columns, select "
- "#%d has %d"
- % (
- 1,
- len(self.selects[0].selected_columns),
- n + 1,
- len(s.selected_columns),
- )
- )
-
- self.selects.append(s.self_group(against=self))
+ self.selects = [
+ coercions.expect(roles.CompoundElementRole, s).self_group(
+ against=self
+ )
+ for s in selects
+ ]
GenerativeSelect.__init__(self, **kwargs)