Skip to content

Numeric value out of range (0) with Decimal types in TVPs #996

@ericblam

Description

@ericblam

Environment

  • Python: 3.8.10 (64-bit)
  • pyodbc: 4.0.32
  • OS: Windows 10 Enterprise
  • DB: Microsoft SQL Server 2014
  • driver: ODBC Driver 17 for SQL Server (version 2017.174.01.01)

Note: Was able to reproduce with same code in the following as well:

  • Python: 3.8.12
  • pyodbc: 4.0.32
  • OS: Red Hat 9.3.1-2
  • DB: Microsoft SQL Server 2014
  • driver: ODBC Driver 17 for SQL Server

Issue

This looks similar to #596 in that pyodbc seems to deduce the type of the TVP from the first row, but seems to do this with precision of Decimals. That is to say if the first row uses '4.000' then '25.000' in the second row (in the same column) is "too big."

Reproduction

from decimal import Decimal

import pyodbc


CONN_STRING = "DRIVER={ODBC Driver 17 for SQL Server};DATABASE=somedatabase;Server=someserver;UID=someuser;PWD=somepassword"

conn = pyodbc.connect(CONN_STRING)
cursor = conn.cursor()
# cursor.execute('CREATE TYPE dbo.DecimalTestingType AS TABLE(val DECIMAL(20,4))')
# cursor.execute('CREATE PROCEDURE dbo.DecimalTestProcedure @Tvp dbo.DecimalTestingType READONLY AS SELECT * FROM @Tvp')

data = [
    [Decimal('4.0000')],
    [Decimal('25.0000')],
]

"""
# Note: Using the following instead succeeds
data = [
    [Decimal('25.0000')],
    [Decimal('4.0000')],
]
"""

# Throws "pyodbc.DataError: ('22003', '[22003] [Microsoft][ODBC Driver 17 for SQL Server]Numeric value out of range (0) (SQLPar
amData)')"
cursor.execute('EXECUTE dbo.DecimalTestProcedure ?', [data])
results = cursor.fetchall()
print(results)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions