rinsed-org / rb-snowflake-client

pure ruby snowflake (REST API) client
MIT License
9 stars 11 forks source link

Impossible to execute INSERT query with json data #31

Closed lizdeika closed 5 months ago

lizdeika commented 7 months ago

Say we have tbl table with a data VARIANT column

json_string = '{"valid": "json"}'
query = "insert into tbl(data) select parse_json('#{json_string}')"
client.query(query)

This will lead to an error something like this:

SQL compilation error:\nInvalid expression [PARSE_JSON('{\"valid\":{\"json\"}')] in VALUES clause

Because of some type of escapement and added slashes to the query

lizdeika commented 6 months ago

https://github.com/rinsed-org/rb-snowflake-client/pull/32

Made a PR for this to be solved:

json_string = '{"valid": "json"}'
query = "insert into tbl(data) select parse_json(?)"
bindings = {
  "1": {
    "type": "TEXT",
    "value": json_string
  }
}
client.query(query, bindings: bindings)
reidnimz commented 5 months ago

@lizdeika appreciate the contribution. It's now available in version 1.1.0