Skip to content

SNOW-2248950: converter.py: parameter binding for decimal.Decimal produces incorrect SQL #2455

@tboddyspargo

Description

@tboddyspargo

Python version

3.11.6

Operating system and processor architecture

macOS-15.5-arm64-arm-64bit

Installed packages

snowflake-connector-python==3.15.0
snowflake-sqlalchemy==1.7.3

What did you do?

engine = sa.create_engine(...)
with engine.connect() as conn:
    result = conn.execute(sa.select(sa.literal(decimal.Decimal('1.3'))))
    resval = result.fetchone()
    assert resval == '1.3' # True - the SQL executed will be `SELECT '1.3'`, so it will return a string literal.

This is caused by:

def _decimal_to_snowflake(self, value: decimal.Decimal) -> str | None:
if isinstance(value, decimal.Decimal):
return str(value)
return None

What did you expect to see?

I expect this query to be executed as SELECT 1.3, not SELECT '1.3'. The bind parameter value of decimal.Decimal('1.3') is not being correctly rendered as a NUMBER contstant/literal. If the decimal.Decimal value was being correctly rendered during client-side parameter binding, then a numeric value (either float or, preferably decimal.Decimal) would be returned, not a str.

Metadata

Metadata

Labels

bugstatus-triage_doneInitial triage done, will be further handled by the driver team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions