Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-16 Thread Mike Bayer
OK, new day, new perspectives. This is the best way to do the mapping / type: class CastToIntegerType(TypeDecorator): impl = String def column_expression(self, col): return cast(col, Integer) def process_bind_param(self, value, dialect): return str(value) class

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-16 Thread Katie Wurman
This is a perfectly usable solution. Thanks so much! On Wednesday, September 16, 2015 at 11:39:57 AM UTC-7, Michael Bayer wrote: > > OK, new day, new perspectives. This is the best way to do the mapping / > type: > > class CastToIntegerType(TypeDecorator): > impl = String > > def

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-15 Thread Katie Wurman
Ok thanks! Adding a bind_expression to my CastToInteger type ensures that when Person.id is included in a WHERE clause, the param is cast to varchar. This is ok, except now I have the following situation: class CastToIntegerType(types.TypeDecorator): impl = types.Numeric def

[sqlalchemy] Cast model id column from String to Integer

2015-09-15 Thread Katie Wurman
Hi, I'm having trouble implementing a model whose 'id' column needs to be cast to Integer type. Below is the implementation I've got so far: class CastToIntegerType(types.TypeDecorator): ''' Converts stored String values to Integer via CAST operation ''' impl = types.Numeric

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-15 Thread Mike Bayer
On 9/15/15 1:19 PM, Katie Wurman wrote: Hi, I'm having trouble implementing a model whose 'id' column needs to be cast to Integer type. Below is the implementation I've got so far: class CastToIntegerType(types.TypeDecorator): ''' Converts stored String values to Integer via CAST

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-15 Thread Mike Bayer
On 9/15/15 4:10 PM, Mike Bayer wrote: On 9/15/15 2:47 PM, Katie Wurman wrote: class Person(Base): __tablename__ = 'person' id = Column('id_string', CastToIntegerType, primary_key=True) pets = relationship('Pets', primaryjoin='foreign(Pets.person_id)==Person.id') class

Re: [sqlalchemy] Cast model id column from String to Integer

2015-09-15 Thread Mike Bayer
On 9/15/15 2:47 PM, Katie Wurman wrote: Ok thanks! Adding a bind_expression to my CastToInteger type ensures that when Person.id is included in a WHERE clause, the param is cast to varchar. This is ok, except now I have the following situation: class CastToIntegerType(types.TypeDecorator):