Skip to content

Any plan to implement VARIANT insert with prepared statement? #244

@cedricwebisoft

Description

@cedricwebisoft

First sorry for my english.

I am trying to insert some json data into a VARIANT field. I tried with a python dict, and a python dict converted to json with json.dumps(). Both failed. Either with

expecting VARIANT but got VARCHAR(16) for column JSON_IMPORT_CONFIG

or with

Python data type [dict] cannot be automatically mapped to Snowflake data type. Specify the snowflake data type explicitly.

Code:

raw_sql = f"INSERT INTO table(col1, col2, json_col) VALUES(?, ?, ?);"
db.execute(raw_sql, (1,2, {'test': 'test'}))

I know we can use parse_json in the sql or something like that, but I feel like the code might be subject to SQL injection this way, and I simplified the code above, but in fact I wrote an ORM over python-snowflake-connector to have a django-like behavior. So I cant tell in advance how many columns I have and where is the json in that, so using parse_json feel very hackish for something like that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleenhancementThe issue is a request for improvement or a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions