Closed gwd closed 6 months ago
First of all, thank you for sqlx -- very useful package!
I've got the following code, which does a batch insert (ss.Discussions is a slice):
res, err := sqlx.NamedExec(eq, ` INSERT INTO event_schedule (discussionid, slotid, locationid) VALUES (:discussionid, :slotid, :locationid)`, ss.Discussions) if err != nil { log.Printf("Failed inserting schedule entries %v", ss.Discussions) return errOrRetry("Adding new schedule entries", err) } if n, err := res.RowsAffected(); err != nil { log.Printf("Error getting rows affected by inserting scheduling entries: %v", err) return errOrRetry("Getting rows affected by inserting schedule entries", err) } else if int(n) != len(ss.Discussions) { log.Printf("Error inserting scheduling entries: Expected %d rows affected, got %d!", len(ss.Discussions), int(n)) return fmt.Errorf("Inserting scheduling entries: Expected %d rows affected, got %d!", len(ss.Discussions), int(n)) }
In v1.3.1, this code works, inserting the expected number of rows; but for v1.3.2 and later, it only inserts a single record. I've tried to make it match the example of batch insert with structs as closely as possible, with no luck. Any ideas?
batch insert with structs
Actually the issue was on a different query, which I've now fixed. Sorry for the noise.
First of all, thank you for sqlx -- very useful package!
I've got the following code, which does a batch insert (ss.Discussions is a slice):
In v1.3.1, this code works, inserting the expected number of rows; but for v1.3.2 and later, it only inserts a single record. I've tried to make it match the example of
batch insert with structs
as closely as possible, with no luck. Any ideas?