Importing and Exporting Data Files on a GSQL Client
When you execute the COPY command to export data on a GSQL client, the generated data files are saved on the database server by default. This can make it difficult for users to access the files. To offer easier file access, the \COPY command directly generates data files on the local client.
Differences Between COPY and \COPY
- File location: The files generated and read during COPY import are located on the server. Conversely, in \COPY import, both the generated and read files are located on the client.
- Performance: To complete \COPY import, the client must read file streams and transmit them to the server. This results in decreased performance in comparison to COPY.
- Functionality: Compared to COPY, \COPY offers an additional capability—client-based parallel import. For detailed specifications and limitations, consult "Database Connection Tools > gsql for Connecting to a Database > Meta-Command Reference" in Tool Reference.
Example \COPY Commands
To export with \COPY, simply replace COPY with \COPY in your commands. Below is a straightforward example of converting CSV export commands from COPY to their \COPY equivalents:
1 2 3 4 5 6 |
-- COPY commands: COPY {data_source} to '/path/export.csv' encoding {server_encoding} csv; COPY {data_source} from '/path/export.csv' encoding {server_encoding} csv; -- Corresponding \COPY commands: \COPY {data_source} to '/path/export.csv' encoding {server_encoding} csv; \COPY {data_source} from '/path/export.csv' encoding {server_encoding} csv; |
Example Commands for Parallel Import
1 2 3 4 5 6 7 8 9 |
-- Import command for the CSV format: \COPY {data_destination} from '/path/export.txt' encoding {file_encoding} parallel {parallel_num} csv; -- Import command for the FIXED format: \COPY {data_destination} from '/path/export.txt' encoding {file_encoding} parallel {parallel_num} fixed; -- Import command for the TEXT format: \COPY {data_destination} from '/path/export.txt' encoding {file_encoding} parallel {parallel_num}; -- data_destination can only be a table name. -- file_encoding indicates the encoding format used during binary file export. -- parallel_num indicates the number of clients for data import. When there are sufficient cluster resources, it is advisable to set it to 8. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot