Skip to content

Instantly share code, notes, and snippets.

@ralfbecher
Last active February 6, 2021 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralfbecher/210408184329d83b37cac309cb4ef2ef to your computer and use it in GitHub Desktop.
Save ralfbecher/210408184329d83b37cac309cb4ef2ef to your computer and use it in GitHub Desktop.
Golang get Snowflake QueryID out of *sql.Rows
import (
"context"
"database/sql"
"database/sql/driver"
"errors"
"reflect"
// ...
sf "github.com/snowflakedb/gosnowflake"
)
// from: https://stackoverflow.com/questions/42664837/how-to-access-unexported-struct-fields/60598827#60598827
func GetUnexportedField(field reflect.Value) interface{} {
return reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface()
}
resultSet, err := s.DB.QueryContext(ctxWithID, statement)
// ...
var queryID string
val := reflect.ValueOf(resultSet).Elem().FieldByName("rowsi")
field := GetUnexportedField(val)
if driverRows, ok := field.(driver.Rows); ok {
queryID = driverRows.(sf.SnowflakeResult).GetQueryID()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment