COPY FILES

statementsupportedData loading & unloading

docs.snowflake.com ↗

Copy files from a source location to an output stage. You can either use a stage or a query as the source of the files to copy. - Use a stage as the source to copy files from one stage to another without renaming. - Use a query as a source for the following tasks: Copy from or to a set of files defined by a query (SELECT statement). - Copy from files written by a UDF (for example, Writing files from Snowpark Python UDFs and UDTFs). - Copy from scoped or stage URLs. You can copy from and to existing named stages, as the following table illustrates: A target or source external stage can reference files in any of the following cloud storage services or on-premises locations: - Amazon S3 - Google Cloud Storage - Microsoft Azure Blob storage - Microsoft Data Lake Storage Gen2 - Microsoft Azure General-purpose v2 - Amazon S3-compatible storage

Syntax

supportedpartialnot supportednot scored

COPY FILES INTO @[<namespace>.]<stage_name>[/<path>/]
  FROM @[<namespace>.]<stage_name>[/<path>/]
  [ FILES = ( '<file_name>' [ , '<file_name>' ] [ , ... ] ) ]
  [ PATTERN = '<regex_pattern>' ]
  [ DETAILED_OUTPUT = { TRUE | FALSE } ]
COPY FILES INTO @[<namespace>.]<stage_name>[/<path>/]
  FROM ( SELECT <existing_url> [ , <new_filename> ] FROM ... )
  [ DETAILED_OUTPUT = { TRUE | FALSE } ]

Parameters

NameRequiredDescription
INTO @[namespace.]stage_name[/path/]requiredSpecifies the target location for the copied files. namespace is the database or schema in which the internal or external stage resides, in the form of database_name.schema_name or schema_name. The namespace is optional if a database and schema are currently in use within the user session; otherwise, it is required. path is an optional, case-sensitive path in the cloud storage location that specifies a set of files to copy from the source stage or a specific location on the target stage. Your cloud storage service might call the path a prefix or a folder. Note If a target or source path name includes special characters or spaces, you must enclose the INTO ... value in single quotes. The values for INTO ... must be literal constants. The values cannot be SQL variables.
FROM @[namespace.]stage_name[/path/]requiredSpecifies the source location where the files to copy are staged. The values provided to FROM ... follow the same specification and constraints as INTO... values.
FROM (SELECT existing_url [ , new_filename ] FROM ... )requiredSpecifies the source location and optional relative output location for the copied files. Each row that the SELECT query returns represents a file to copy. existing_url is a scoped URL, stage name, or stage URL. new_filename is an optional relative path from the output stage specified for the INTO clause. Snowflake copies the file to the following location: @[<namespace>.]<stage_name>[/<path>]<new_filename> If you don’t specify a value for new_filename, Snowflake uses the relative path of the existing_url.
FILES = ( 'file_name' [ , 'file_name' ... ] )optionalSpecifies a list of one or more comma-separated file names to copy. The files must already be staged in the source location that you specify in the command. Snowflake skips any specified files that can’t be found. You can specify a maximum of 1000 file names. Copy files from query does not support this option. Instead, use the query to provide the filename list. Note To set the file path for external stages, Snowflake prepends the URL in the stage definition to each file name in the list. However, Snowflake does not insert a separator between the path and file name. You must explicitly include a separator (/) at the end of the URL in the stage definition or at the beginning of each file name in the FILES list.
PATTERN = 'regex_pattern'optionalSpecifies a regular expression pattern for filtering the list of files to copy. This command applies the regular expression to the entire storage location in the FROM clause. Copy files from query does not support this option. Instead, use the query to match the pattern. Tip For best performance, avoid patterns that filter on a large number of files.
DETAILED_OUTPUT = { TRUE | FALSE }optionalSpecifies whether the command output should summarize the results of the copy operation or list each file copied. Values: If TRUE, the output includes a row for each file copied to the target location. A single column named file contains the target path (if applicable) and file name for each copied file. If FALSE, the output is a single row with the number of files that were copied. Default: TRUE

Usage notes

Access control requirements

A role used to execute this SQL command must have the following privileges (depending on the source and target locations) at a minimum: Privilege | Object | Notes USAGE | External stage | Required on a source or target external stage. READ | Internal named stage | Required on a source internal stage. WRITE | Internal named stage | Required on a target internal stage. Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

See also

Referenced by