@@ -43,6 +43,10 @@ func (qq *QueuedQuery) QueryRow(fn func(row Row) error) {
4343}
4444
4545// Exec sets fn to be called when the response to qq is received.
46+ //
47+ // Note: for simple batch insert uses where it is not required to handle
48+ // each potential error individually, it's sufficient to not set any callbacks,
49+ // and just handle the return value of BatchResults.Close.
4650func (qq * QueuedQuery ) Exec (fn func (ct pgconn.CommandTag ) error ) {
4751 qq .Fn = func (br BatchResults ) error {
4852 ct , err := br .Exec ()
@@ -83,7 +87,7 @@ func (b *Batch) Len() int {
8387
8488type BatchResults interface {
8589 // Exec reads the results from the next query in the batch as if the query has been sent with Conn.Exec. Prefer
86- // calling Exec on the QueuedQuery.
90+ // calling Exec on the QueuedQuery, or just calling Close .
8791 Exec () (pgconn.CommandTag , error )
8892
8993 // Query reads the results from the next query in the batch as if the query has been sent with Conn.Query. Prefer
@@ -98,6 +102,9 @@ type BatchResults interface {
98102 // QueuedQuery.Query, QueuedQuery.QueryRow, or QueuedQuery.Exec will be called. If a callback function returns an
99103 // error or the batch encounters an error subsequent callback functions will not be called.
100104 //
105+ // For simple batch inserts inside a transaction or similar queries, it's sufficient to not set any callbacks,
106+ // and just handle the return value of Close.
107+ //
101108 // Close must be called before the underlying connection can be used again. Any error that occurred during a batch
102109 // operation may have made it impossible to resyncronize the connection with the server. In this case the underlying
103110 // connection will have been closed.
0 commit comments