2

How do I tell SqlAlchemy not to convert Oracle Number fields to Decimal when querying an Oracle database?

I'm trying to replace a bunch of code containing hand-rolled sql-statements, with SqlAlchemy. A lot of the queries deal get 500 columns of Numbers from the database. The SQL alchemy version, using their pooled connection, is 10 times slower, almost certainly because of the conversion to Decimal.

>>> engine = sqlalchemy.create_engine("oracle+cx_oracle://"+connString)
>>> conn = engine.pool.connect()
>>> cursor = conn.cursor()
>>> cursor.execute("""SELECT * FROM MY_TABLE""")
>>> r = cursor.fetchone()
>>> r[-1]
Decimal('0.878935370620606')

How do I tell the dialect not to make the conversion to Decimal? (The old code doesn't use decimal, so the loss in precision isn't important. The factor of 10 slowdown is.)

AFoglia
  • 7,968
  • 3
  • 35
  • 51
  • 1
    I've tried setting `engine.dialect.supports_native_decimal` to `False`, but that doesn't work. I'm guessing SqlAlchemy is pre-computing the conversion functions. – AFoglia Feb 05 '12 at 22:40

1 Answers1

0

I also asked this on the SqlAlchemy list, and got a good answer. There was no way, but the developer added one quickly. Also, he suggested using the cDecimal python library as a much faster, drop-in replacement for the standard library decimal module.

AFoglia
  • 7,968
  • 3
  • 35
  • 51