isinstance(column, sql.Function)):
result_expr = _CompileLabel(col_expr, column.anon_label)
elif col_expr is not column:
- result_expr = _CompileLabel(col_expr, column.anon_label)
+ # TODO: are we sure "column" has a .name and .key here ?
+ # assert isinstance(column, sql.ColumnClause)
+ result_expr = _CompileLabel(col_expr,
+ sql._as_truncated(column.name),
+ alt_names=(column.key,))
else:
result_expr = col_expr
iswrapper=False, fromhints=None,
compound_index=0,
positional_names=None, **kwargs):
-
entry = self.stack and self.stack[-1] or {}
existingfroms = entry.get('from', None)
-from sqlalchemy import Table, Column, String, func, MetaData, select, TypeDecorator
+from sqlalchemy import Table, Column, String, func, MetaData, select, TypeDecorator, cast
from test.lib import fixtures, AssertsCompiledSQL, testing
from test.lib.testing import eq_
self.assert_compile(
select([table]),
- "SELECT test_table.x, lower(test_table.y) AS y_1 FROM test_table"
+ "SELECT test_table.x, lower(test_table.y) AS y FROM test_table"
+ )
+
+ def test_anonymous_expr(self):
+ table = self._fixture()
+ self.assert_compile(
+ select([cast(table.c.y, String)]),
+ "SELECT CAST(test_table.y AS VARCHAR) AS anon_1 FROM test_table"
)
def test_select_cols_use_labels(self):
table = self._fixture()
self.assert_compile(
select([table]).where(table.c.y == "hi"),
- "SELECT test_table.x, lower(test_table.y) AS y_1 FROM "
- "test_table WHERE test_table.y = lower(:y_2)"
+ "SELECT test_table.x, lower(test_table.y) AS y FROM "
+ "test_table WHERE test_table.y = lower(:y_1)"
)
class RoundTripTestBase(object):
"Y1"
)
+ def test_targeting_by_string(self):
+ testing.db.execute(
+ self.tables.test_table.insert(),
+ {"x": "X1", "y": "Y1"},
+ )
+ row = testing.db.execute(select([self.tables.test_table])).first()
+ eq_(
+ row["y"],
+ "Y1"
+ )
+
def test_targeting_apply_labels(self):
testing.db.execute(
self.tables.test_table.insert(),