Skip to content

Casting to sa.Float (and some other types) silently does nothing #151

Closed
@DelongChenQC

Description

@DelongChenQC

When explicitly using the cast function to cast something into a sa.Float, the engine silently ignores this command and instead does nothing. This is especially dangerous when working with bind parameters as the implicit casting, does not work.
E.g:

metadata = sa.MetaData()
table = sa.Table(table_input, metadata, schema=schema_name, autoload_with=engine)

int_column_1 = table.int_column_1
int_column_2 = table.int_column_2

problem_query = sa.cast(int_column_1 / int_column_2, sa.Float) / 1_000_000

When now executing this query, one would expect a float outcome, however due to the way the

def visit_cast(self, cast, **kw):
function is written. It throws out the casting, leading to a silent error.

What is the reasoning for only having a set number of types that casting is possible to?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions