Question

I'm connecting to an proprietary MSSQL database using python, sqlalchemy and pymssql. The database cannot be edited and I only need to read data from it. Now my programme spits out this message when it first runs a query on the database.

path/to/sqlalchemy/dialects/mssql/pymssql.py:50: SAWarning: Dialect mssql+pymssql does *not* support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal numbers as strings or integers on this platform for lossless storage.
  return sqltypes.Numeric.result_processor(self, dialect, type_)

I understand this is sqlalchemy speaking to me and it means that when I read data from a field of type Decimal that it will be converted to a Float and rounded in the process.

So I have two questions about this...

Firstly, on a Linux machine is there a way to get Decimal data from an MSSQL database without this problem?

Secondly, why is the programme printing this message rather than crashing or raising an exception? If I can cope with this small error then how do I stop the message constantly being spat out at me?

Was it helpful?

Solution

yes. use the pyodbc (free/OSS) or mxodbc (commercial, use mxodbc in 0.8 only with the latest mxodbc) dialects, they've been tested as delivering DECIMAL objects with full precision. pymssql is currently an unknown, as this DBAPI has undergone many rewrites/ownership changes and its status is a little up in the air.

also, the warning is because you can get decimal objects back, they will just be subject to the usual floating point weirdnesses (like 3.456 coming back as 3.4559999999999 type of thing). So better to allow the values to be read with caveats than to block what is otherwise partially working functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top