Skip to content

Commit 38a9e11

Browse files
committed
Bug fix
1 parent cfd1a87 commit 38a9e11

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

Diff for: server/connection_handler.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -675,16 +675,14 @@ func (h *ConnectionHandler) copyFromFileQuery(stmt *node.CopyFrom) error {
675675
return err
676676
}
677677

678-
// TODO: rather than always committing the transaction here, we should respect whether a transaction was
679-
// expliclitly started and not commit if not. In order to do that, we need to not always set
680-
// ctx.GetIgnoreAutoCommit(), and instead conditionally *not* insert a transaction closing iterator during chunk
681-
// processing. We need a new query flag to effectively do the latter though.
682-
txSession, ok := sqlCtx.Session.(sql.TransactionSession)
683-
if !ok {
684-
return fmt.Errorf("session does not implement sql.TransactionSession")
685-
}
686-
if err = txSession.CommitTransaction(sqlCtx, txSession.GetTransaction()); err != nil {
687-
return err
678+
if sqlCtx.GetTransaction() != nil && !sqlCtx.GetIgnoreAutoCommit() {
679+
txSession, ok := sqlCtx.Session.(sql.TransactionSession)
680+
if !ok {
681+
return fmt.Errorf("session does not implement sql.TransactionSession")
682+
}
683+
if err = txSession.CommitTransaction(sqlCtx, txSession.GetTransaction()); err != nil {
684+
return err
685+
}
688686
}
689687

690688
return h.send(&pgproto3.CommandComplete{

0 commit comments

Comments
 (0)