-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SNOW-176486 How to insert a map[string]string in a variant column? #217
Comments
Hi @vgrigoriu , the error is thrown from https://golang.org/src/database/sql/driver/types.go line 281. Which means using DB interface does not support map type. Besides that, we don't support binding VARIANT on the golang driver for now. You can directly send a query containing the variant if that match you needs. See https://docs.snowflake.net/manuals/sql-reference/data-types-semistructured.html for more info on that. We will keep this thread open and upgrade here once we support binding VARIANT type. |
this is with the driver team already so reopened this issue to properly track the progress when it's any |
small update: this turns out to be a new feature request, looking at https://github.com/snowflakedb/gosnowflake/blob/master/bind_uploader.go#L292 // TODO SNOW-176486 variant, object, array so thank you everyone for bearing with us while this gets put on the roadmap and eventually worked on. The workaround will be converting map[string]string to a JSON string and inserting VARIANT data directly using "INSERT INTO ... SELECT": Example: param := map[string]string{"key": "value"}
jsonStr, _ := json.Marshal(param)
db.Exec("create or replace table issue_296(c1 variant)")
result, err := db.Exec(
"INSERT INTO issue_296 (c1) SELECT TO_VARIANT(PARSE_JSON(?));",
string(jsonStr),
) |
@sfc-gh-dszmolka Thanks! Just curious, why |
good catch, should be of no difference, but testing should prove or disprove this assumption |
Issue description
I'm trying to insert a Go
map
in a Snowflake column of typeVARIANT
. I get an error sayingfailed to run query: sql: converting argument $2 type: unsupported type map[string]string, a map
.Example code
Configuration
Driver version (or git SHA): latest
Go version: go1.10.1 darwin/amd64
Server version: 3.12.0
Client OS: macos
The text was updated successfully, but these errors were encountered: