title: How to wrap a column in a CAST operation
body: <p>I have an MSSQL database with tables which I cannot change and only ever interact with it as read only (SELECT statements). I am using sqlalchemy. What I need to do is to automatically wrap specific columns in CAST() SQL operations for every query. I want to do this at a low level so my code never needs to think about the problem. The reason I am doing this is explained in <a href="https://stackoverflow.com/questions/18785670/can-i-use-pyodbc-freetds-and-sqlalchemy-with-decimal-data-in-mssql">this question</a>.</p>
  
  <p>My table is something like this:</p>
  
  <pre><code>from sqlalchemy import Column, Integer, Sequence
  from sqlalchemy.ext.declarative import declarative_base
  
  Base = declarative_base()
  
  class myTable(Base):
      __tablename__ = u'mytable'
      id = Column(Integer, Sequence('table_id_seq'), primary_key=True)
      problem_field = Column(DECIMAL(12, 4), nullable=True)
  </code></pre>
  
  <p>I have been trying to use a TypeDecorator like this:</p>
  
  <pre><code>from sqlalchemy import Column, Integer, Sequence, types
  from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy.sql.expression import cast
  
  Base = declarative_base()
  
  class CastToFloatType(types.TypeDecorator):
      '''Converts stored Decimal values to Floats via CAST operation
      '''
      impl = types.Numeric
      def column_expression(self, col):
          return cast(col, Float)
  
  class myTable(Base):
      __tablename__ = u'mytable'
      id = Column(Integer, Sequence('table_id_seq'), primary_key=True)
      wrapped_field = Column(CastToFloatType, nullable=True)
  </code></pre>
  
  <p>But it doesn't seem to do anything.</p>