I have a structure that holds an array of class objects which I uploaded to my BigQuery table using inferschema
. However, I am now trying to iterate through that table and update the values accordingly and I am not able to access the column which holds the array of class objects.
I have already tried to access it using different class names such as:
- "Reviewers[0].Role"
- "`Reviewers[0].Role`"
- "Reviewers_0.Role"
- "Reviewers(0).Role"
... None of which works
//Models which I'm using for the schema of the tables
type PullRequest struct {
Reviewers []*Reviewer `json:"reviewers"`
}
type Reviewer struct {
Role string `json:"role"`
Status string `json:"status"`
User *User `json:"user"`
}
//Putting sql statements in constant to avoid SQL injection
const (
prUpdateSQL = "UPDATE %s.%s.%s"
prSetSQL = "SET %v = '%v'"
prSetNonEscapeSQL = "%v = %v"
prSetEscapeSQL = "%v = '%v'"
prWhereSQL = "WHERE ID = %v"
)
commandstring := fmt.Sprintf(prUpdateSQL+" ", projectID, datasetID, tableName)
for i, r := range pr.Reviewers{
reviewerString := fmt.Sprintf("Reviewers.%d", i)
commandstring += fmt.Sprintf(prSetEscapeSQL+", ", reviewerString+".Role", r.Role)
commandstring += fmt.Sprintf(prSetEscapeSQL+", ", reviewerString+".Status", r.Status)
commandstring += fmt.Sprintf(prSetEscapeSQL+", ", reviewerString+".User.Name", r.User.Name)
}
I am expecting the results to be able to set the different class objects values in the array to my new value which pr holds. Instead I get this error message:
UPDATE ... SET does not support array modification with [] at [1:914], invalidQuery"