Check your version of MySQLdb. MySQLdb returns the Decimal directly, perhaps that wasn't the case for older versions.
from sqlalchemy import * from decimal import Decimal engine = create_engine("mysql://scott:tiger@localhost/test", strategy='threadlocal', pool_recycle=10, encoding='utf-8', convert_unicode=True, paramstyle='pyformat', echo=True) metadata = MetaData(engine) table = Table('foo', metadata, Column('id', Integer, primary_key=True), Column('latitude', Numeric(precision=12, scale=9,asdecimal=True), nullable=True), mysql_engine='InnoDB') metadata.drop_all() metadata.create_all() table.insert().values(latitude=Decimal("34.5")).execute() c = engine.connect() cursor = c.connection.cursor() cursor.execute("select * from foo") print cursor.fetchall() CREATE TABLE foo ( id INTEGER NOT NULL AUTO_INCREMENT, latitude NUMERIC(12, 9), PRIMARY KEY (id) )ENGINE=InnoDB 2011-01-17 14:14:50,787 INFO sqlalchemy.engine.threadlocal.TLEngine.0x...d8b0 {} 2011-01-17 14:14:50,789 INFO sqlalchemy.engine.threadlocal.TLEngine.0x...d8b0 COMMIT 2011-01-17 14:14:50,789 INFO sqlalchemy.engine.threadlocal.TLEngine.0x...d8b0 INSERT INTO foo (latitude) VALUES (%(latitude)s) 2011-01-17 14:14:50,789 INFO sqlalchemy.engine.threadlocal.TLEngine.0x...d8b0 {'latitude': Decimal('34.5')} 2011-01-17 14:14:50,790 INFO sqlalchemy.engine.threadlocal.TLEngine.0x...d8b0 COMMIT ((1L, Decimal('34.500000000')),) On Jan 17, 2011, at 1:09 PM, The Dude wrote: > Hi, > > Thank you for SQLAlchemy. I've had a great experience with it so far. > > I'm running into an issue where I've declared the column type to use > decimal.Decimal but I get float back from select. > > I'd appreciate any clues you might have. > > url = 'mysql://%s:%s@%s:%d/%s' % (cfg['login'], cfg['password'], > cfg['host'], cfg['port'], cfg['database']) > engine = create_engine(url, strategy='threadlocal', pool_recycle=10, > encoding='utf-8', convert_unicode=True, paramstyle='pyformat') > table = Table('foo', metadata, > Column('id', Integer, primary_key=True), > Column('latitude', Numeric(precision=12, scale=9, > asdecimal=True), nullable=True), > mysql_engine='InnoDB') > query = table.select().where(table.c.id == bindparam('id')) > result = engine.execute(query, id = 34) > row = result.fetchone() > print type(row.latitude) > #prints <type 'float'> > > Thanks, > > Roger > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalchemy@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.