.. changelog::
:version: 1.0.7
+ .. change::
+ :tags: feature, sql
+ :tickets: 3459
+ :pullreq: bitbucket:56
+
+ Added a :meth:`.ColumnElement.cast` method which performs the same
+ purpose as the standalone :func:`.cast` function. Pull request
+ courtesy Sebastian Bank.
+
.. change::
:tags: bug, engine
:tickets: 3481
def cast(self, type_):
"""Produce a type cast, i.e. ``CAST(<expression> AS <type>)``.
- This is a shortcut to the :func:`.cast` function.
+ This is a shortcut to the :func:`~.expression.cast` function.
+
+ .. versionadded:: 1.0.7
+
"""
return Cast(self, type_)
'Incorrect number of expected results')
eq_(str(cast(tbl.c.v1, Numeric).compile(dialect=dialect)),
'CAST(casttest.v1 AS %s)' % expected_results[0])
+ eq_(str(tbl.c.v1.cast(Numeric).compile(dialect=dialect)),
+ 'CAST(casttest.v1 AS %s)' % expected_results[0])
eq_(str(cast(tbl.c.v1, Numeric(12, 9)).compile(dialect=dialect)),
'CAST(casttest.v1 AS %s)' % expected_results[1])
eq_(str(cast(tbl.c.ts, Date).compile(dialect=dialect)),
"SELECT CAST(test_table.y AS VARCHAR) AS anon_1 FROM test_table"
)
- def test_cast_method(self):
- table = self._fixture()
- self.assert_compile(
- select([table.c.y.cast(String)]),
- "SELECT CAST(test_table.y AS VARCHAR) AS anon_1 FROM test_table"
- )
-
def test_select_cols_use_labels(self):
table = self._fixture()