使用 Oracle DB 在 SqlAlchemy 中关闭自动转换为十进制
在查询 Oracle 数据库时,如何告诉 SqlAlchemy 不将 Oracle Number 字段转换为 Decimal?
我正在尝试用 SqlAlchemy 替换一堆包含手动 sql 语句的代码。许多查询都会从数据库中获取 500 列数字。 SQL alchemy 版本使用其池化连接,速度慢了 10 倍,几乎可以肯定是因为转换为十进制。
>>> 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')
如何告诉方言不要转换为十进制? (旧代码不使用十进制,因此精度损失并不重要。减速因素 10 才是。)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还在 SqlAlchemy 列表上提出了这个问题,并得到了好的答案。没办法,但开发商很快就加了一个。此外,他建议使用 cDecimal python 库作为更快的直接替代品标准库十进制模块。
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.