COPY INTO <LOCATION>

statementpartialData loading & unloading

docs.snowflake.com ↗

Unloads data from a table (or query) into one or more files in one of the following locations: - Named internal stage (or table/user stage). The files can then be downloaded from the stage/location using the GET command. - Named external stage that references an external location (Amazon S3, Google Cloud Storage, or Microsoft Azure). - External location (Amazon S3, Google Cloud Storage, or Microsoft Azure).

Syntax

supportedpartialnot supportednot scored

COPY INTO { internalStage | externalStage | externalLocation }
     FROM { [<namespace>.]<table_name> | ( <query> ) }
[ PARTITION BY <expr> ]
[ FILE_FORMAT = ( { FORMAT_NAME = '[<namespace>.]<file_format_name>' |
                    TYPE = { CSV | JSON | PARQUET } [ formatTypeOptions ] } ) ]
[ copyOptions ]
[ VALIDATION_MODE = RETURN_ROWS ]
[ HEADER ]

Where

internalStage ::=
    @[<namespace>.]<int_stage_name>[/<path>]
  | @[<namespace>.]%<table_name>[/<path>]
  | @~[/<path>]

Where

externalStage ::=
  @[<namespace>.]<ext_stage_name>[/<path>]

Where

externalLocation (for Amazon S3) ::=
  '<protocol>://<bucket>[/<path>]'
  [ { STORAGE_INTEGRATION = <integration_name> } | { CREDENTIALS = ( {  { AWS_KEY_ID = '<string>' AWS_SECRET_KEY = '<string>' [ AWS_TOKEN = '<string>' ] } } ) } ]
  [ ENCRYPTION = ( [ TYPE = 'AWS_CSE' ] [ MASTER_KEY = '<string>' ] |
                   [ TYPE = 'AWS_SSE_S3' ] |
                   [ TYPE = 'AWS_SSE_KMS' [ KMS_KEY_ID = '<string>' ] ] |
                   [ TYPE = 'NONE' ] ) ]

Where

externalLocation (for Google Cloud Storage) ::=
  'gcs://<bucket>[/<path>]'
  [ STORAGE_INTEGRATION = <integration_name> ]
  [ ENCRYPTION = ( [ TYPE = 'GCS_SSE_KMS' ] [ KMS_KEY_ID = '<string>' ] | [ TYPE = 'NONE' ] ) ]

Where

externalLocation (for Microsoft Azure) ::=
  'azure://<account>.blob.core.windows.net/<container>[/<path>]'
  [ { STORAGE_INTEGRATION = <integration_name> } | { CREDENTIALS = ( [ AZURE_SAS_TOKEN = '<string>' ] ) } ]
  [ ENCRYPTION = ( [ TYPE = { 'AZURE_CSE' | 'NONE' } ] [ MASTER_KEY = '<string>' ] ) ]

Where

formatTypeOptions ::=
-- If FILE_FORMAT = ( TYPE = CSV ... )
     COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONE
     RECORD_DELIMITER = '<string>' | NONE
     FIELD_DELIMITER = '<string>' | NONE
     FILE_EXTENSION = '<string>'
     ESCAPE = '<character>' | NONE
     ESCAPE_UNENCLOSED_FIELD = '<character>' | NONE
     DATE_FORMAT = '<string>' | AUTO
     TIME_FORMAT = '<string>' | AUTO
     TIMESTAMP_FORMAT = '<string>' | AUTO
     BINARY_FORMAT = HEX | BASE64 | UTF8
     FIELD_OPTIONALLY_ENCLOSED_BY = '<character>' | NONE
     NULL_IF = ( '<string1>' [ , '<string2>' , ... ] )
     EMPTY_FIELD_AS_NULL = TRUE | FALSE
-- If FILE_FORMAT = ( TYPE = JSON ... )
     COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONE
     FILE_EXTENSION = '<string>'
-- If FILE_FORMAT = ( TYPE = PARQUET ... )
     COMPRESSION = AUTO | LZO | SNAPPY | NONE
     SNAPPY_COMPRESSION = TRUE | FALSE

Where

copyOptions ::=
     OVERWRITE = TRUE | FALSE
     SINGLE = TRUE | FALSE
     MAX_FILE_SIZE = <num>
     INCLUDE_QUERY_ID = TRUE | FALSE
     DETAILED_OUTPUT = TRUE | FALSE

Parameters

NameRequiredDescription
INTO ...requiredSpecifies the internal or external location where the data files are unloaded:
FROM ...requiredSpecifies the source of the data to be unloaded, which can either be a table or a query:
  • ( query ) — SELECT statement that returns data to be unloaded into files. You can limit the number of rows returned by specifying a LIMIT / FETCH clause in the query. Note When casting column values to a data type using the CAST , :: function, verify the data type supports all of the column values. Values too long for the specified data type could be truncated.
[namespace.]table_nameSpecifies the name of the table from which data is unloaded. Namespace optionally specifies the database and/or schema in which the table resides, in the form of database_name.schema_name or schema_name. It is optional if a database and schema are currently in use within the user session; otherwise, it is required.
STORAGE_INTEGRATION = integration_name or CREDENTIALS = ( cloud_specific_credentials )requiredSupported when the COPY statement specifies an external storage URI rather than an external stage name for the target cloud storage location. Specifies the security credentials for connecting to the cloud provider and accessing the private storage container where the unloaded files are staged.Required only for unloading into an external private cloud storage location; not required for public buckets/containers Amazon S3 Google Cloud Storage Microsoft Azure
STORAGE_INTEGRATION = integration_nameSpecifies the name of the storage integration used to delegate authentication responsibility for external cloud storage to a Snowflake identity and access management (IAM) entity. For more details, see CREATE STORAGE INTEGRATION. Note Snowflake recommends the use of storage integrations. This option avoids the need to supply cloud storage credentials using the CREDENTIALS parameter when creating stages or loading data.
CREDENTIALS = ( AWS_KEY_ID = 'string' AWS_SECRET_KEY = 'string' [ AWS_TOKEN = 'string' ] ) or CREDENTIALS = ( AWS_ROLE = 'string' )Specifies the security credentials for connecting to AWS and accessing the private S3 bucket where the unloaded files are staged. For more information, see Configuring secure access to Amazon S3. The credentials you specify depend on whether you associated the Snowflake access permissions for the bucket with an AWS IAM (Identity & Access Management) user or role: IAM user: Temporary IAM credentials are required. Temporary (aka “scoped”) credentials are generated by AWS Security Token Service (STS) and consist of three components: AWS_KEY_ID AWS_SECRET_KEY AWS_TOKEN All three are required to access a private bucket. After a designated period of time, temporary credentials expire and can no longer be used. You must then generate a new set of valid temporary credentials. Important COPY commands contain complex syntax and sensitive information, such as credentials. In addition, they are executed frequently and are often stored in scripts or worksheets, which could lead to sensitive information being inadvertently exposed. The COPY command allows permanent (aka “long-term”) credentials to be used; however, for security reasons, do not use permanent credentials in COPY commands. Instead, use temporary credentials. If you must use permanent credentials, use external stages, for which credentials are entered once and securely stored, minimizing the potential for exposure. IAM role: Omit the security credentials and access keys and, instead, identify the role using AWS_ROLE and specify the AWS role ARN (Amazon Resource Name). Important The ability to use an AWS IAM role to access a private S3 bucket to load or unload data is now deprecated (i.e. support will be removed in a future release, TBD). Snowflake recommends modifying any existing S3 stages that use this feature to instead reference storage integration objects. For instructions, see Option 1: Configure a Snowflake storage integration to access Amazon S3.
STORAGE_INTEGRATION = integration_nameSpecifies the name of the storage integration used to delegate authentication responsibility for external cloud storage to a Snowflake identity and access management (IAM) entity. For more details, see CREATE STORAGE INTEGRATION.
STORAGE_INTEGRATION = integration_nameSpecifies the name of the storage integration used to delegate authentication responsibility for external cloud storage to a Snowflake identity and access management (IAM) entity. For more details, see CREATE STORAGE INTEGRATION. Note Snowflake recommends the use of storage integrations. This option avoids the need to supply cloud storage credentials using the CREDENTIALS parameter when creating stages or loading data.
CREDENTIALS = ( AZURE_SAS_TOKEN = 'string' )Specifies the SAS (shared access signature) token for connecting to Azure and accessing the private container where the files containing data are staged. Credentials are generated by Azure.
ENCRYPTION = ( cloud_specific_encryption )requiredFor use in ad hoc COPY statements (statements that do not reference a named external stage). Required only for unloading data to files in encrypted storage locations Amazon S3 ENCRYPTION = ( [ TYPE = 'AWS_CSE' ] [ MASTER_KEY = '<string>' ] | [ TYPE = 'AWS_SSE_S3' ] | [ TYPE = 'AWS_SSE_KMS' [ KMS_KEY_ID = '<string>' ] ] | [ TYPE = 'NONE' ] ) Google Cloud StorageENCRYPTION = ( [ TYPE = 'GCS_SSE_KMS' | 'NONE' ] [ KMS_KEY_ID = 'string' ] ) Microsoft AzureENCRYPTION = ( [ TYPE = 'AZURE_CSE' | 'NONE' ] [ MASTER_KEY = 'string' ] )
TYPE = ...Specifies the encryption type used. Possible values are: AWS_CSE: Client-side encryption (requires a MASTER_KEY value). Currently, the client-side master key you provide can only be a symmetric key. Note that, when a MASTER_KEY value is provided, Snowflake assumes TYPE = AWS_CSE (i.e. when a MASTER_KEY value is provided, TYPE is not required). AWS_SSE_S3: Server-side encryption that requires no additional encryption settings. AWS_SSE_KMS: Server-side encryption that accepts an optional KMS_KEY_ID value. For more information about the encryption types, see the AWS documentation for client-side encryption or server-side encryption. NONE: No encryption.
MASTER_KEY = 'string' (applies to AWS_CSE encryption only)Specifies the client-side master key used to encrypt the files in the bucket. The master key must be a 128-bit or 256-bit key in Base64-encoded form.
KMS_KEY_ID = 'string' (applies to AWS_SSE_KMS encryption only)Optionally specifies the ID for the AWS KMS-managed key used to encrypt files unloaded into the bucket. If no value is provided, your default KMS key ID is used to encrypt files on unload. Note that this value is ignored for data loading.
TYPE = ...Specifies the encryption type used. Possible values are: GCS_SSE_KMS: Server-side encryption that accepts an optional KMS_KEY_ID value. For more information, see the Google Cloud documentation: https://cloud.google.com/storage/docs/encryption/customer-managed-keys https://cloud.google.com/storage/docs/encryption/using-customer-managed-keys NONE: No encryption.
KMS_KEY_ID = 'string' (applies to GCS_SSE_KMS encryption only)Optionally specifies the ID for the Cloud KMS-managed key that is used to encrypt files unloaded into the bucket. If no value is provided, your default KMS key ID set on the bucket is used to encrypt files on unload. This value is ignored for data loading. The load operation should succeed if the service account has sufficient permissions to decrypt data in the bucket.
TYPE = ...Specifies the encryption type used. Possible values are: AZURE_CSE: Client-side encryption (requires a MASTER_KEY value). For information, see the Client-side encryption information in the Microsoft Azure documentation. NONE: No encryption.
MASTER_KEY = 'string' (applies to AZURE_CSE encryption only)Specifies the client-side master key used to encrypt files. The master key must be a 128-bit or 256-bit key in Base64-encoded form.
PARTITION BY exproptionalSpecifies an expression used to partition the unloaded table rows into separate files. Supports any SQL expression that evaluates to a string. The unload operation splits the table rows based on the partition expression and determines the number of files to create based on the amount of data and number of parallel operations, distributed among the compute resources in the warehouse. Filenames are prefixed with data_ and include the partition column values. Individual filenames in each partition are identified with a universally unique identifier (UUID). The UUID is the query ID of the COPY statement used to unload the data files. Caution COPY INTO <location> statements write partition column values to the unloaded file names. Snowflake recommends partitioning your data on common data types such as dates or timestamps rather than potentially sensitive string or integer values. Note that file URLs are included in the internal logs that Snowflake maintains to aid in debugging issues when customers create Support cases. As a result, data in columns referenced in a PARTITION BY expression is also indirectly stored in internal logs. These logs might be processed outside of your deployment region. Hence, as a best practice, only include dates, timestamps, and Boolean data types in PARTITION BY expressions. If you prefer to disable the PARTITION BY parameter in COPY INTO <location> statements for your account, please contact Snowflake Support. Note that Snowflake provides a set of parameters to further restrict data unloading operations: PREVENT_UNLOAD_TO_INLINE_URL prevents ad hoc data unload operations to external cloud storage locations (i.e. COPY INTO <location> statements that specify the cloud storage URL and access settings directly in the statement). PREVENT_UNLOAD_TO_INTERNAL_STAGES prevents data unload operations to any internal stage, including user stages, table stages, or named internal stages. For an example, see Partitioning Unloaded Rows to Parquet Files (in this topic). Note The following copy option values are not supported in combination with PARTITION BY: OVERWRITE = TRUE SINGLE = TRUE INCLUDE_QUERY_ID = FALSE Including the ORDER BY clause in the SQL statement in combination with PARTITION BY does not guarantee that the specified order is preserved in the unloaded files. If the PARTITION BY expression evaluates to NULL, the partition path in the output filename is _NULL_ (e.g. mystage/_NULL_/data_01234567-0123-1234-0000-000000001234_01_0_0.snappy.parquet). When unloading to files of type PARQUET: Small data files unloaded by parallel execution threads are merged automatically into a single file that matches the MAX_FILE_SIZE copy option value as closely as possible. All row groups are 128 MB in size. A row group is a logical horizontal partitioning of the data into rows. There is no physical structure that is guaranteed for a row group. A row group consists of a column chunk for each column in the dataset. The unload operation attempts to produce files as close in size to the MAX_FILE_SIZE copy option setting as possible. The default value for this copy option is 16 MB. Note that this behavior applies only when unloading data to Parquet files. VARIANT columns are converted into simple JSON strings. Casting the values to an array (using the TO_ARRAY function) results in an array of JSON strings. There is no option to omit the columns in the partition expression from the unloaded data files.
FILE_FORMAT = ( FORMAT_NAME = 'file_format_name' ) or FILE_FORMAT = ( TYPE = CSV | JSON | PARQUET [ ... ] )optionalSpecifies the format of the data files containing unloaded data: Note JSON can only be used to unload data from columns of type VARIANT (i.e. columns containing JSON data). Nested data in VARIANT columns is unloaded to Parquet as a JSON-encoded string. For more information, see Unload a relational table to Parquet with multiple columns.
FORMAT_NAME = 'file_format_name'Specifies an existing named file format to use for unloading data from the table. The named file format determines the format type (CSV, JSON, PARQUET), as well as any other format options, for the data files. For more information, see CREATE FILE FORMAT.
TYPE = CSV | JSON | PARQUETSpecifies the type of files unloaded from the table. If a format type is specified, you can specify additional format-specific options. For information, see Format Type Options (in this topic).
copyOptionsoptionalSpecifies one or more copy options for the unloaded data. For more details, see Copy Options (in this topic).
VALIDATION_MODE = RETURN_ROWSoptionalString (constant) that instructs the COPY command to return the results of the query in the SQL statement instead of unloading the results to the specified cloud storage location. The only supported validation option is RETURN_ROWS. This option returns all rows produced by the query. When you have validated the query, you can remove the VALIDATION_MODE to perform the unload operation.
HEADER = TRUE | FALSEoptionalSpecifies whether to include the table column headings in the output files. Set this option to TRUE to include the table column headings to the output files. Note that if the COPY operation unloads the data to multiple files, the column headings are included in every file. When unloading data in Parquet format, the table column names are retained in the output files. Set this option to FALSE to specify the following behavior: CSV: Do not include table column headings in the output files. Parquet: Include generic column headings (e.g. col1, col2, etc.) in the output files. Default: FALSE
COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONEString (constant) that specifies to compresses the unloaded data files using the specified compression algorithm. Supported Values Notes AUTO Unloaded files are automatically compressed using the default, which is gzip. GZIP BZ2 BROTLI Must be specified when loading Brotli-compressed files. ZSTD Zstandard v0.8 (and higher) supported. DEFLATE Unloaded files are compressed using Deflate (with zlib header, RFC1950). RAW_DEFLATE Unloaded files are compressed using Raw Deflate (without header, RFC1951). NONE Unloaded files are not compressed.ExpandShow lessSee more Default: AUTO
RECORD_DELIMITER = 'string' | NONEOne or more singlebyte or multibyte characters that separate records in an unloaded file. Accepts common escape sequences or the following singlebyte or multibyte characters: Singlebyte characters: Octal values (prefixed by \\) or hex values (prefixed by 0x or \x). For example, for records delimited by the circumflex accent (^) character, specify the octal (\\136) or hex (0x5e) value. Multibyte characters: Hex values (prefixed by \x). For example, for records delimited by the cent (¢) character, specify the hex (\xC2\xA2) value. The delimiter for RECORD_DELIMITER or FIELD_DELIMITER cannot be a substring of the delimiter for the other file format option (e.g. FIELD_DELIMITER = 'aa' RECORD_DELIMITER = 'aabb'). The specified delimiter must be a valid UTF-8 character and not a random sequence of bytes. Also note that the delimiter is limited to a maximum of 20 characters. Also accepts a value of NONE. Default: New line character. Note that “new line” is logical such that \r\n is understood as a new line for files on a Windows platform.
FIELD_DELIMITER = 'string' | NONEOne or more singlebyte or multibyte characters that separate fields in an unloaded file. Accepts common escape sequences or the following singlebyte or multibyte characters: Singlebyte characters: Octal values (prefixed by \\) or hex values (prefixed by 0x or \x). For example, for fields delimited by the circumflex accent (^) character, specify the octal (\\136) or hex (0x5e) value. Multibyte characters: Hex values (prefixed by \x). For example, for fields delimited by the cent (¢) character, specify the hex (\xC2\xA2) value. The delimiter for RECORD_DELIMITER or FIELD_DELIMITER cannot be a substring of the delimiter for the other file format option (e.g. FIELD_DELIMITER = 'aa' RECORD_DELIMITER = 'aabb'). Note For non-ASCII characters, you must use the hex byte sequence value to get a deterministic behavior.
FILE_EXTENSION = 'string'String that specifies the extension for files unloaded to a stage. Accepts any extension. The user is responsible for specifying a valid file extension that can be read by the desired software or service. Note If the SINGLE copy option is TRUE, then the COPY command unloads a file without a file extension by default. To specify a file extension, provide a file name and extension in the internal_location or external_location path. For example: copy into @stage/data.csv ... Default: null, meaning the file extension is determined by the format type, e.g. .csv[compression], where compression is the extension added by the compression method, if COMPRESSION is set.
DATE_FORMAT = 'string' | AUTOString that defines the format of date values in the unloaded data files. If a value is not specified or is set to AUTO, the value for the DATE_OUTPUT_FORMAT parameter is used. Default: AUTO
TIME_FORMAT = 'string' | AUTOString that defines the format of time values in the unloaded data files. If a value is not specified or is set to AUTO, the value for the TIME_OUTPUT_FORMAT parameter is used. Default: AUTO
TIMESTAMP_FORMAT = 'string' | AUTOString that defines the format of timestamp values in the unloaded data files. If a value is not specified or is set to AUTO, the value for the TIMESTAMP_OUTPUT_FORMAT parameter is used. Default: AUTO
BINARY_FORMAT = HEX | BASE64 | UTF8String (constant) that defines the encoding format for binary output. The option can be used when unloading data from binary columns in a table. Default: HEX
ESCAPE = 'character' | NONEUse: Data loading and unloading Definition: A singlebyte character string used as the escape character for enclosed or unenclosed field values. An escape character invokes an alternative interpretation on subsequent characters in a character sequence. You can use the ESCAPE character to interpret instances of the FIELD_OPTIONALLY_ENCLOSED_BY character in the data as literals. The escape character can also be used to escape instances of itself in the data. Accepts common escape sequences, octal values, or hex values. Specify the character used to enclose fields by setting FIELD_OPTIONALLY_ENCLOSED_BY. If this option is set, it overrides the escape character set for ESCAPE_UNENCLOSED_FIELD. Default: NONE
ESCAPE_UNENCLOSED_FIELD = 'character' | NONEUse: Data loading and unloading Definition: A singlebyte character string used as the escape character for unenclosed field values only. An escape character invokes an alternative interpretation on subsequent characters in a character sequence. You can use the ESCAPE character to interpret instances of the FIELD_DELIMITER or RECORD_DELIMITER characters in the data as literals. The escape character can also be used to escape instances of itself in the data. Accepts common escape sequences, octal values, or hex values. If ESCAPE is set, the escape character set for that file format option overrides this option. Default: backslash (\\)
FIELD_OPTIONALLY_ENCLOSED_BY = 'character' | NONECharacter used to enclose strings. Value can be NONE, single quote character ('), or double quote character ("). To use the single quote character, use the octal or hex representation (0x27) or the double single-quoted escape (''). When a field in the source table contains this character, Snowflake escapes it using the same character for unloading. For example, if the value is the double quote character and a field contains the string A "B" C, Snowflake escapes the double quotes for unloading as follows: A ""B"" C Default: NONE
NULL_IF = ( 'string1' [ , 'string2' ... ] ) | ()String used to convert from SQL NULL. Snowflake converts SQL NULL values to the first value in the list. If NULL_IF = () is specified, Snowflake converts NULL values to empty fields (,,). Default: \N (that is, NULL, which assumes the ESCAPE_UNENCLOSED_FIELD value is \ (default))
EMPTY_FIELD_AS_NULL = TRUE | FALSEUsed in combination with FIELD_OPTIONALLY_ENCLOSED_BY. When FIELD_OPTIONALLY_ENCLOSED_BY = NONE, setting EMPTY_FIELD_AS_NULL = FALSE specifies to unload empty strings in tables to empty string values without quotes enclosing the field values. If set to TRUE, FIELD_OPTIONALLY_ENCLOSED_BY must specify a character to enclose strings. Default: TRUE
COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONEString (constant). Compresses the data file using the specified compression algorithm. Supported Values Notes AUTO Unloaded files are automatically compressed using the default, which is gzip. GZIP BZ2 BROTLI ZSTD DEFLATE Unloaded files are compressed using Deflate (with zlib header, RFC1950). RAW_DEFLATE Unloaded files are compressed using Raw Deflate (without header, RFC1951). NONE Unloaded files are not compressed.ExpandShow lessSee more Default: AUTO
FILE_EXTENSION = 'string' | NONEString that specifies the extension for files unloaded to a stage. Accepts any extension. The user is responsible for specifying a valid file extension that can be read by the desired software or service. Default: null, meaning the file extension is determined by the format type (e.g. .json[compression]), where compression is the extension added by the compression method, if COMPRESSION is set.
COMPRESSION = AUTO | LZO | SNAPPY | NONEString (constant). Compresses the data file using the specified compression algorithm. Supported Values Notes AUTO Files are compressed using Snappy, the default compression algorithm. LZO Files are compressed using the Snappy algorithm by default. If applying Lempel-Ziv-Oberhumer (LZO) compression instead, specify this value. SNAPPY Files are compressed using the Snappy algorithm by default. You can optionally specify this value. NONE Specifies that the unloaded files are not compressed.ExpandShow lessSee more Default: AUTO
SNAPPY_COMPRESSION = TRUE | FALSEBoolean that specifies whether the unloaded file(s) are compressed using the SNAPPY algorithm. Note Deprecated. Use COMPRESSION = SNAPPY instead. Default: TRUE
OVERWRITE = TRUE | FALSEDefinition: Boolean that specifies whether the COPY command overwrites existing files with matching names, if any, in the location where files are stored. The option does not remove any existing files that do not match the names of the files that the COPY command unloads. In many cases, enabling this option helps prevent data duplication in the target stage when the same COPY INTO <location> statement is executed multiple times. However, when an unload operation writes multiple files to a stage, Snowflake appends a suffix that ensures each file name is unique across parallel execution threads (e.g. data_0_1_0). The number of parallel execution threads can vary between unload operations. If the files written by an unload operation do not have the same filenames as files written by a previous operation, SQL statements that include this copy option cannot replace the existing files, resulting in duplicate files. In addition, in the rare event of a machine or network failure, the unload job is retried. In that scenario, the unload operation writes additional files to the stage without first removing any files that were previously written by the first attempt. To avoid data duplication in the target stage, we recommend setting the INCLUDE_QUERY_ID = TRUE copy option instead of OVERWRITE = TRUE and removing all data files in the target stage and path (or using a different path for each unload operation) between each unload job. Default: FALSE
SINGLE = TRUE | FALSEDefinition: Boolean that specifies whether to generate a single file or multiple files. If FALSE, a filename prefix must be included in path. Important If SINGLE = TRUE, then COPY ignores the FILE_EXTENSION file format option and outputs a file simply named data. To specify a file extension, provide a filename and extension in the internal or external location path. For example:Copy code COPY INTO @mystage/data.csv ... In addition, if the COMPRESSION file format option is also explicitly set to one of the supported compression algorithms (e.g. GZIP), then the specified internal or external location path must end in a filename with the corresponding file extension (e.g. gz) so that the file can be uncompressed using the appropriate tool. For example:Copy code COPY INTO @mystage/data.gz ... COPY INTO @mystage/data.csv.gz ... Default: FALSE
MAX_FILE_SIZE = numDefinition: Specifies the target maximum size (in bytes) of each file to be generated in parallel per thread. Snowflake utilizes parallel execution to optimize performance. The number of threads can’t be modified. Note The actual unloaded file size and number of files unloaded depends on the total amount of data and number of nodes available for parallel processing. The unloaded file size depends on the available memory in the warehouse worker, which varies based on: The warehouse size and available resources. The number of concurrent queries running on the warehouse. MAX_FILE_SIZE doesn’t enforce a hard cap. Snowflake tries to keep each unloaded file at or below the size you set, but a file can be smaller when memory constraints require earlier completion. A file can also be slightly larger than that size, including when you set MAX_FILE_SIZE to the maximum of 5368709120 (5 GB). A storage provider that enforces a strict size limit can reject a file that exceeds the provider’s limit. If that happens, set MAX_FILE_SIZE to a value slightly smaller than the provider’s size limit. The COPY command unloads one set of table rows at a time. If you set a very small MAX_FILE_SIZE value (for example, less than 1 MB), the amount of data in a set of rows could exceed the specified size. Default: 16777216 (16 MB) Maximum: 5368709120 (5 GB)
INCLUDE_QUERY_ID = TRUE | FALSEDefinition: Boolean that specifies whether to uniquely identify unloaded files by including a universally unique identifier (UUID) in the filenames of unloaded data files. This option helps ensure that concurrent COPY statements do not overwrite unloaded files accidentally. Values: If TRUE, a UUID is added to the names of unloaded files. The UUID is the query ID of the COPY statement used to unload the data files. The UUID is a segment of the filename: <path>/data_<uuid>_<name>.<extension>. This option also prevents unloading duplicate data if an internal retry occurs. When an internal retry occurs, Snowflake deletes the partial set of unloaded files (identified by UUID), then restarts the copy operation. If FALSE, then a UUID is not added to the unloaded data files. Note INCLUDE_QUERY_ID = TRUE is the default copy option value when you partition the unloaded table rows into separate files (by setting PARTITION BY expr in the COPY INTO <location> statement). This value cannot be changed to FALSE. INCLUDE_QUERY_ID = TRUE is not supported when either of the following copy options is set: SINGLE = TRUE OVERWRITE = TRUE In the rare event of a machine or network failure, the unload job is retried. In that scenario, the unload operation removes any files that were written to the stage with the UUID of the current query ID and then attempts to unload the data again. Any new files written to the stage have the retried query ID as the UUID. Default: FALSE
DETAILED_OUTPUT = TRUE | FALSEDefinition: Boolean that specifies whether the command output should describe the unload operation or the individual files unloaded as a result of the operation. Values: If TRUE, the command output includes a row for each file unloaded to the specified stage. Columns show the path and name for each file, its size, and the number of rows that were unloaded to the file. If FALSE, the command output consists of a single row that describes the entire unload operation. Columns show the total amount of data unloaded from tables, before and after compression (if applicable), and the total number of rows that were unloaded. Default: FALSE

Usage notes

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.

See also

Referenced by