exported to the columns collection of an enclosing
select() construct, or if any construct involving
that column is compiled before its name is
- assigned. [ticket:1862]
+ assigned.
+
+ - as_scalar(), label() can be called on a selectable
+ which contains a Column that is not yet named.
+ [ticket:1862]
- engine
def __init__(self, element):
self.element = element
- cols = list(element.c)
- self.type = cols[0].type
+ self.type = element._scalar_type()
@property
def columns(self):
self.selects.append(s.self_group(self))
_SelectBaseMixin.__init__(self, **kwargs)
-
+
+ def _scalar_type(self):
+ return self.selects[0]._scalar_type()
+
def self_group(self, against=None):
return _FromGrouping(self)
return froms
+ def _scalar_type(self):
+ elem = self._raw_columns[0]
+ cols = list(elem._select_iterable)
+ return cols[0].type
+
@property
def froms(self):
"""Return the displayed list of FromClause elements."""
lambda: sel1.c
)
+ # calling label or as_scalar doesn't compile
+ # anything.
+ sel2 = select([func.substr(my_str, 2, 3)]).label('my_substr')
+
assert_raises_message(
exc.CompileError,
"Cannot compile Column object until it's 'name' is assigned.",
- lambda: select([func.substr(my_str, 2, 3)]).label('my_substr')
+ str, sel2
)
+ sel3 = select([my_str]).as_scalar()
assert_raises_message(
- exc.InvalidRequestError,
- "Cannot initialize a sub-selectable with this Column",
- lambda: select([my_str]).as_scalar()
+ exc.CompileError,
+ "Cannot compile Column object until it's 'name' is assigned.",
+ str, sel3
)
-
my_str.name = 'foo'
self.assert_compile(
"SELECT foo",
)
self.assert_compile(
- select([func.substr(my_str, 2, 3)]).label('my_substr'),
+ sel2,
'(SELECT substr(foo, :substr_2, :substr_3) AS substr_1)',
)
+ self.assert_compile(
+ sel3,
+ "(SELECT foo)"
+ )
+
def test_naming(self):
f1 = func.hoho(table1.c.name)
s1 = select([table1.c.myid, table1.c.myid.label('foobar'),