-
Notifications
You must be signed in to change notification settings - Fork 25
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
Unable to scan into an array of struct #309
Comments
Looks like upstream code does work: client := must(spanner.NewClient(ctx, "projects/"+ProjectID+"/instances/"+InstanceID+"/databases/"+DatabaseName))
defer client.Close()
type Entry struct {
Name string
Value int64
}
input := []Entry{
{Name: "Hello", Value: 1000},
{Name: "World", Value: 2000},
}
rows := client.ReadOnlyTransaction().Query(ctx, spanner.Statement{
SQL: `SELECT ARRAY(SELECT AS STRUCT Name, Value FROM UNNEST(@input)) AS entries`,
Params: map[string]any{
"input": input,
},
})
for {
row, err := rows.Next()
if err != nil {
fmt.Fprintln(os.Stderr, err)
break
}
var output []*Entry // NOTE: []Entry does not work
if err := row.Columns(&output); err != nil {
fmt.Fprintln(os.Stderr, err)
}
for _, entry := range output {
fmt.Println(entry)
}
} |
It does look like that supporting that behavior is difficult with the current An alternative would be to instead pass
The Line 268 in c39f57f
The drawback for this approach is that when you use |
Scanning array of spanner structs into a slice of Go structs doesn't seem to be working. Smallest reproducer:
This fails with:
If the code is changed to use
TO_JSON
andspanner.NullJSON
it is able to return the correct values.It's unclear whether the issue is in go-sql-spanner or upstream.
The text was updated successfully, but these errors were encountered: