Description
Version
1.14.0
What happened?
If a query in the new :batchexec
causes an error, batch.Exec runs in an infinite loop.
I think this is caused by this (generated code):
func (b *MyBatchResults) Exec(f func(int, error)) {
for {
_, err := b.br.Exec()
if err != nil && (err.Error() == "no result" || err.Error() == "batch already closed") {
break
}
if f != nil {
f(b.ind, err)
}
b.ind++
}
}
it only exits if no result/closed. if there is some error, but a "real error" that is not one of these two, the for loop will keep running forever.
a workaround i found is calling Close() on the batch BEFORE running exec. But i am not convinced this is the right way; pgx' tests do run Close only after the right amount of Exec() calls have been made : https://github.com/jackc/pgx/blob/master/batch_test.go
Possible fix could be: when creating the batch, the generated code saves the number of items in the batch into the batch struct. When running exec, the for loop exits if enough calls have been made.
Any opinions? I could probably contribute a fix, if it can be confirmed that my assumptions here are correct.
Relevant log output
1103466 ERROR: duplicate key value violates unique constraint "<redacted>" (SQLSTATE 23505)
### Database schema
_No response_
### SQL queries
_No response_
### Configuration
_No response_
### Playground URL
_No response_
### What operating system are you using?
_No response_
### What database engines are you using?
_No response_
### What type of code are you generating?
_No response_