Skip to content

Insert Decimal with executemany throw an error #272

@Tweentyy

Description

@Tweentyy

Describe the bug

When attempting to add a Decimal to the database with an executemany, an error is returned.

Exception message: Exception: RuntimeError: Input string UTF-16 length exceeds allowed column size at parameter index 0. UTF-16 length: 20, Column size: 13
Stack trace:
[2025-10-02T10:57:39.569Z]   File "/Users/tweenty/Desktop/XXX/test.py", line 31, in insert_data
[2025-10-02T10:57:39.570Z]     cursor.executemany("INSERT INTO TestSQL (DecimalTest) VALUES (?)", data)
[2025-10-02T10:57:39.570Z]   File "/Users/tweenty/Desktop/XXX/.venv/lib/python3.12/site-packages/mssql_python/cursor.py", line 1682, in executemany
[2025-10-02T10:57:39.570Z]     ret = ddbc_bindings.SQLExecuteMany(
[2025-10-02T10:57:39.570Z] .

To reproduce

Create a table with Decimal:

CREATE TABLE TestSQL (
	DecimalTest DECIMAL(30, 20)
)
from decimal import Decimal

data = [(Decimal('35.1128407822'),), (Decimal('40000.56405640654065'),)]

cursor.execute("INSERT INTO TestSQL (DecimalTest) VALUES (?)", data[0]) # Works
cursor.executemany("INSERT INTO TestSQL (DecimalTest) VALUES (?)", data) # Doesn't work

Workaround found - Convert Decimal to str :

from decimal import Decimal

data = [(str(Decimal('35.1128407822')),), (str(Decimal('40000.56405640654065')),)]

cursor.execute("INSERT INTO TestSQL (DecimalTest) VALUES (?)", data[0]) # Works
cursor.executemany("INSERT INTO TestSQL (DecimalTest) VALUES (?)", data) # Works

Expected behavior

Insertion of lines into database.

Further technical details

Python version: 3.12.10
SQL Server version: SQL Server 2022
Operating system: macOS 26.0.1
mssql_python version: 0.13.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtriage doneIssues that are triaged by dev team and are in investigation.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions