| 839 | "column_list_specified", columnList != "", |
| 840 | ) |
| 841 | c.logWorkerStatementStarted(workerStatement) |
| 842 | result, err := c.executor.Exec(copySQL) |
| 843 | var copyRowsAffected int64 |
| 844 | if result != nil { |
| 845 | copyRowsAffected, _ = result.RowsAffected() |
| 846 | } |
| 847 | c.logWorkerStatementFinished(workerStatement, loadStart, copyRowsAffected, err) |
| 848 | if err != nil { |
| 849 | c.logger().Error("COPY FROM STDIN DuckDB COPY failed.", "error", err) |
| 850 | errMsg := fmt.Sprintf("COPY failed: %v", err) |
| 851 | c.sendError("ERROR", "22P02", errMsg) |
| 852 | c.setTxError() |
| 853 | c.logQuery(copyStartTime, query, query, "COPY", 0, int64(rowCount), "22P02", errMsg, "simple") |
| 854 | _ = c.writeReadyForQuery(c.txStatus) |
| 855 | _ = c.flushWriter() |
| 856 | return nil |
| 857 | } |
| 858 | |
| 859 | rowCount = int(copyRowsAffected) |
| 860 | |
| 861 | totalElapsed := time.Since(copyStartTime) |
| 862 | loadElapsed := time.Since(loadStart) |
| 863 | c.logger().Info("COPY FROM STDIN completed.", "rows", rowCount, "total_duration", totalElapsed, "load_duration", loadElapsed) |
| 864 | |
| 865 | _ = c.writeCommandComplete(fmt.Sprintf("COPY %d", rowCount)) |
| 866 | c.logQuery(copyStartTime, query, query, "COPY", 0, int64(rowCount), "", "", "simple") |
| 867 | _ = c.writeReadyForQuery(c.txStatus) |
| 868 | _ = c.flushWriter() |
| 869 | return nil |
| 870 | |
| 871 | case wire.MsgCopyFail: |
| 872 | // Client cancelled COPY |
| 873 | errMsg := string(bytes.TrimRight(body, "\x00")) |
| 874 | exception := fmt.Sprintf("COPY failed: %s", errMsg) |
| 875 | c.sendError("ERROR", "57014", exception) |
| 876 | c.setTxError() |
| 877 | c.logQuery(copyStartTime, query, query, "COPY", 0, int64(rowCount), "57014", exception, "simple") |
| 878 | _ = c.writeReadyForQuery(c.txStatus) |
| 879 | _ = c.flushWriter() |
| 880 | return nil |
| 881 | |
| 882 | default: |
| 883 | errMsg := fmt.Sprintf("unexpected message type during COPY: %c", msgType) |
| 884 | c.sendError("ERROR", "08P01", errMsg) |