question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQL Server money precision must be 4

See original GitHub issue
  • Python: 3.7.0
  • pyodbc: 4.0.24
  • OS: Linux
  • DB: Microsoft SQL Server 2008 R2 (SP3) - 10.50.6220.0 (X64)
  • driver: FreeTDS
db = pyodbc.connect(my_connection_string)
sql = 'SELECT CAST(0.1234 AS money)'
print(db.execute(sql).fetchall()[0]) 

# outputs (Decimal('0.12'), )
# expected (Decimal('0.1234'), )

All MSSQL versions should have 4-digits precision for money type

Is this configurable maybe? Thank you!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
studentikscommented, Sep 24, 2018

Oh my, hope it’s in the right place now )

1reaction
v-chojascommented, Sep 24, 2018
		Entry:
			Statement = 0x5606ab1f2f30
			Column Number = 1
			Target Type = -8 SQL_WCHAR
			Buffer Length = 4096
			Target Value = 0x5606ab219380
			StrLen Or Ind = 0x7ffcdd9b4a20
[ODBC][32335][1537818877.979645][SQLGetData.c][545]
		Exit:[SQL_SUCCESS]                
			Buffer = [0.12](unicode)                
			Strlen Or Ind = 0x7ffcdd9b4a20 -> 8

This is fault of ODBC driver, not pyODBC. pyODBC is asking driver to return result in character format and driver is returning character string “0.12” which has truncated the precision already.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should you choose the MONEY or DECIMAL(x,y) datatypes in ...
I'm aware that money is specific to SQL Server. I want to know if there is a compelling reason to choose one over...
Read more >
Precision, scale, and length (Transact-SQL) - Microsoft Learn
In SQL Server, the default maximum precision of numeric and ... For example, an int data type can hold 10 digits, is stored...
Read more >
Avoid use of the MONEY and SMALLMONEY datatypes (BP022)
Use of the MONEY and SMALLMONEY datatypes can lead to unintentional loss of precision, due to rounding errors, during calculations.
Read more >
SQL Money Data Type: What Is It? What About Decimal?
The MONEY data type in SQL Server is shrouded in mystery. What is it for? When should you avoid it? What advantages does...
Read more >
What is the difference between Decimal (19, 4) and Money ...
I suggested that,we should consider using DECIMAL (19, 4). ... is the difference between Decimal (19, 4) and Money Data type in SQL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found