microsoft / microsoft/mssql-python

Bulk Copy Handles Decimal Inconsistently Compared with Normal Queries

Open
#457 3 comments 0 reactions 1 assignee View on GitHub

@Theekshna is already working on this.

Since Mar 2, 2026.

area: bulk-copy triage needed
Dominant language
Python
Stars
472
Forks
60
Avg merge
2d 11h
Merged PRs (30d)
36

Description

Describe the bug

Trying to insert into a Decimal column with the new bulk_copy can throw an exception regarding mismatched decimal scale, whereas a normal insert will succeed and automatically deal with the issue. I would like to see bulk_copy work similarly and seamlessly.

To reproduce
import mssql_python
from decimal import Decimal

conn = mssql_python.connect([conn string], autocommit=True)
cur = conn.cursor()
cur.execute('create table dectest (d decimal(10, 2));')

# This next line works fine
cur.execute('insert into dectest values (?)', Decimal('123.456'))

# This line fails with the below exception
cur.bulkcopy('dectest', (Decimal('123.456'),))
Exception message
ValueError: Input decimal scale 3 exceeds target scale 2
Expected behavior

The bulkcopy should succeed and the value should be automatically rounded as it is in the insert.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.