COPY FILES INTO VOLUME
Overview
Copies existing files verbatim from one Volume to another (file content is preserved — not parsed or reformatted). Commonly used to move files between external Volumes (OSS/COS/S3), Managed Volumes, USER VOLUMEs, and TABLE VOLUMEs — for example, transferring an archived file from object storage into a table's staging area before importing it, or backing up files between Volumes.
Unlike COPY INTO VOLUME (which exports a table or query result as files), this command has a Volume as both source and destination, copies files as-is, does not involve table data, and does not take a FILE_FORMAT.
Syntax
Parameters
-
Destination Volume (
INTO): choose one of the three Volume types.VOLUME <volume_name>: an external Volume (OSS/COS/S3) or a Managed Volume.TABLE VOLUME <table_name>: the staging Volume of the specified table.USER VOLUME: the current user's USER VOLUME.SUBDIRECTORY '<dest_path>': optional, destination subdirectory; when omitted, files are written to the root of the destination Volume.
-
Source Volume (
FROM): choose one of the three Volume types; it may differ from the destination type (cross-type copy is supported).SUBDIRECTORY '<src_path>': optional, copies only files under the specified subdirectory of the source Volume.
-
File filter (
FILESandREGEXPare mutually exclusive; both optional):FILES = ( '<file_name>' [, ...] ): specify files by exact name, relative to the source (sub)directory. If any file in the list does not exist, the whole operation fails withCZLH-70002: File not found.REGEXP = '<pattern>': match files by their relative path with a regular expression.
Return Value
On success, returns a single file column listing the relative path of each copied file within the source Volume.
Notes
- The
FILESkeyword is required: you must writeFILESbetweenCOPYandINTO. WritingCOPY INTO VOLUME ... FROM VOLUMEis parsed as the table-export syntax and raises a syntax error. - Overwrites by default: an existing file with the same name in the destination Volume is overwritten; the operation is idempotent on repeated runs. There is no
OVERWRITEkeyword. - Destination keeps only the file name: the source subdirectory hierarchy is not retained; the file lands under the destination
SUBDIRECTORY. - Missing source file fails: if any file in the
FILESlist does not exist in the source, the whole command fails.
Examples
Prerequisites: create two Volumes and place files in the source Volume.
Copy a single file (simplest form):
Copy multiple files into a subdirectory:
Copy with a regular expression (note REGEXP = with the equals sign):
Copy from a subdirectory of the source Volume (the returned file is the source-relative path):
Copy all files recursively when no filter is given:
Copy across Volume types — copy a file from an external Volume to a USER VOLUME:
Copy a file into a table's TABLE VOLUME staging area, then import it with COPY INTO:
Verify the result with SHOW VOLUME DIRECTORY:
Related Documentation
- Export Data to VOLUME - COPY INTO VOLUME: export a table or query result as files to a Volume
- Import Data from VOLUME to Table - COPY INTO TABLE: import files from a Volume into a table
- Volume Introduction: Volume concepts and operations
