yes, looking at psycopg2's source code i can see that its checking for python 2.4 and then using Decimal:
if sys.version_info[0] >= 2 and sys.version_info[1] >= 4: define_macros.append(('HAVE_DECIMAL','1')) #ifdef HAVE_DECIMAL PyObject *decimal = PyImport_ImportModule("decimal"); if (decimal) { decimalType = PyObject_GetAttrString(decimal, "Decimal"); } #endif So, I did a test locally with PG and confirmed that you do in fact get a Decimal back when using Py2.4: db = create_engine('postgres://scott:[EMAIL PROTECTED]/test?echo=True') table = Table('sometable', db, Column('col1', Numeric)) db.create(table) db.execute(table.insert(), dict(col1=2.5)) x = db.connect().scalar(table.select()) print type(x) print x <class 'decimal.Decimal'> 2.50 The Numeric types in SQLAlchemy dont modify the incoming or outgoing return type of bind parameters at all. this disagrees with your initial assertion that you get a "float" type back....so...do you have a test case ? is it possible you are assigning a "float" to a mapped object and then just getting back that same float without any DB round trip going on ? On Jun 3, 2006, at 3:42 AM, Yuan HOng wrote: > Thanks for pointing this out. I found out that psycopg 1.1.21 gives > back a Numeric as float. When I switched to psycopg2, a Decimal object > is automatically returned. > > I was switching from SQLObjects, and there the Numeric is > automatically converted to Decimal seemingly by SQLObjects, so I took > that for granted. Maybe this should also be added to SA, since then > the application won't be dependant on the return type of the DBAPI > layer? > > On 6/3/06, Michael Bayer <[EMAIL PROTECTED]> wrote: >> the float type coming from Numeric etc. is straight from the DBAPI, >> in this case psycopg2. If youd like to make your own Decimal type >> which translates this value back and forth from whatever float value >> psycopg2 is giving you, simply subclass TypeDecorator, specify >> Numeric as the 'impl', and implement the appropriate >> convert_bind_param(), convert_result_value() methods. >> >> instructions are here: >> >> http://www.sqlalchemy.org/docs/types.myt#types_custom >> >> if you get that done, theres no reason it cant be stuck into the >> types module, just wouldnt be available if youre on 2.3. >> > -- > Hong Yuan > > 大管家网上建材超市 > 装修装潢建材一站式购物 > http://www.homemaster.cn _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users