handleCopyDone handles a COPY DONE message by finalizing the in-progress COPY DATA operation and committing the loaded table data. The |stop| response parameter is true if the connection handler should shut down the connection, |endOfMessages| is true if no more COPY DATA messages are expected, and
(_ *pgproto3.CopyDone)
| 880 | return false, false, fmt.Errorf("no COPY FROM STDIN node found") |
| 881 | } |
| 882 | table := h.copyFromStdinState.targetTable |
| 883 | if table == nil { |
| 884 | return false, true, fmt.Errorf("no target table found") |
| 885 | } |
| 886 | rawOptions := h.copyFromStdinState.rawOptions |
| 887 | |
| 888 | switch copyFrom.Options.CopyFormat { |
| 889 | case CopyFormatArrow: |
| 890 | dataLoader, err = NewArrowDataLoader( |
| 891 | sqlCtx, h.duckHandler, |
| 892 | copyFrom.Table.Schema(), table, copyFrom.Columns, |
| 893 | rawOptions, |
| 894 | ) |
| 895 | case tree.CopyFormatText: |
| 896 | // Remove `\.` from the end of the message data, if it exists |
| 897 | if bytes.HasSuffix(message.Data, []byte{'\\', '.', '\n'}) { |
| 898 | message.Data = message.Data[:len(message.Data)-3] |
| 899 | } |
| 900 | if bytes.HasSuffix(message.Data, []byte{'\\', '.', '\r', '\n'}) { |
| 901 | message.Data = message.Data[:len(message.Data)-4] |
| 902 | } |
| 903 | fallthrough |
| 904 | case tree.CopyFormatCSV: |
| 905 | dataLoader, err = NewCsvDataLoader( |
| 906 | sqlCtx, h.duckHandler, |
| 907 | copyFrom.Table.Schema(), table, copyFrom.Columns, |
| 908 | ©From.Options, |
| 909 | rawOptions, |
| 910 | ) |
| 911 | case tree.CopyFormatBinary: |
| 912 | err = fmt.Errorf("BINARY format is not supported for COPY FROM") |
| 913 | default: |
| 914 | err = fmt.Errorf("unknown format specified for COPY FROM: %v", copyFrom.Options.CopyFormat) |
| 915 | } |
| 916 | |
| 917 | if err != nil { |
| 918 | return false, false, err |
| 919 | } |
| 920 | |
| 921 | ready := dataLoader.Start() |
no test coverage detected