Skip to main content

COPY INTO <table>

Use the copy option parameters to load data to an existing table. Supported parameters are listed below and are used by external_table, pipe, and stage.

Usage

External table

external_tables:
EXTERNAL_TABLE_1:
file_format:
format_type: "CSV"
compression: "AUTO"
field_delimiter: ","
skip_header: 1
skip_blank_lines: false
location:
database: "DATABASE_1"
schema: "SCHEMA_1"
stage: "STAGE_1"
path: "lifecycle_runner"
columns:
Name:
type: "text"
as: "(value:c1::text)"
Year:
type: "text"
as: "(value:c2::text)"
comment: "Test external table"
auto_refresh: true
copy_grants: false
refresh_on_create: true
grants:
SELECT:
- ROLE_1
REFERENCES:
- ROLE_2

Pipe

pipes:
PIPE_1:
comment: A pipe.
error_integration: "NOTIFICATION_INTEGRATION_1"
auto_ingest: false
copy_statement:
into:
database: "DATABASE_2"
schema: "SCHEMA_2"
table: "TABLE_1"
from:
database: "DATABASE_1"
schema: "SCHEMA_1"
stage: "STAGE_1"
select_statement: "SELECT $1, $2"
pattern: ".*[.]csv"
file_format:
type: "CSV"
compression: "AUTO"
enforce_length: false
truncate_columns: true
grants:
MONITOR:
- ROLE_1
OPERATE:
- ROLE_2

Stage using the existing file format

stages:
STAGE_1:
url: "s3://{{AWS.EXAMPLE.S3_BUCKET}}"
credentials: "AWS_KEY_ID='{{AWS.EXAMPLE.ACCESS_KEY_ID}}' AWS_SECRET_KEY='{{AWS.EXAMPLE.SECRET_ACCESS_KEY}}'"
file_format:
format_name: "FILE_FORMAT_1"
grants:
USAGE:
- ROLE_1
- ROLE_2

Stage using none existing file format

stages:
STAGE_2:
url: "s3://{{AWS.EXAMPLE.S3_BUCKET}}"
credentials: "AWS_KEY_ID='{{AWS.EXAMPLE.ACCESS_KEY_ID}}' AWS_SECRET_KEY='{{AWS.EXAMPLE.SECRET_ACCESS_KEY}}'"
file_format:
type: "CSV"
compression: "AUTO"
record_delimiter: "\n"
field_delimiter: ","
binary_format: HEX
encoding: "UTF8"
escape_unenclosed_field: none
skip_header: 0
escape: "\\\\"
field_optionally_enclosed_by: '"'
date_format: "AUTO"
time_format: "AUTO"
timestamp_format: "AUTO"
validate_utf8: true
grants:
USAGE:
- ROLE_1

Supported parameters

Configuration KeyRequired/OptionalData Type and Values
fromRequiredSee here for a definition of from
intoRequiredSee here for a definition of into
enforce_lengthOptionalBoolean
file_formatOptionalSee here for a definition of file_format
forceOptionalBoolean
match_by_column_nameOptionalString: CASE_SENSITIVE, CASE_INSENSITIVE, NONE
on_errorOptionalString
patternOptional<regex_pattern>
purgeOptionalBoolean
return_failed_onlyOptionalBoolean
size_limitOptionalInteger
truncate_columnsOptionalBoolean

from parameters

Configuration KeyRequired/OptionalData Type and ValuesDescription
databaseRequired - if the stage is present in another database or schemaStringName of the database in which the stage exists
schemaRequired - if the stage is present in another database or SchemaStringName of the schema in which the table exists
stageRequiredStringName of the external stage
select_statementOptionalStringSpecifies the select statement for the pipe only. It will load data from the select query.
pathOptionalStringSpecifies the path for the pipe only.

into parameters

Configuration KeyRequired/OptionalData Type and ValuesDescription
databaseRequired - if the table is present in another database or schemaStringName of the database in which the table exists
schemaRequired - if the table is present in another Database or SchemaStringName of the schema in which the table exists
tableRequiredStringName of the table

file_format parameters

Configuration KeyRequired/OptionalData Type and ValuesDescription
format_databaseRequired - if the format name is present in another database or schemaStringName of the format database in which the file format exists
format_schemaRequired - if format_database is presentStringName of the format schema in which the file format exists
format_nameRequired - if format_database and format_schema are presentStringName of the file format.
Note: format_name and type are mutually exclusive and cannot be specified simultaneously in the same copy_statement configuration.
typeRequired - if format_database, format_schema, and format_name are not presentString: CSV, JSONFormat of the data files to load.
Note: format_name and type are mutually exclusive and cannot be specified simultaneously in the same copy_statement configuration.
allow_duplicateOptionalBooleanAllows duplicate object field names
binary_as_textOptionalBooleanSpecifies whether to interpret columns with no defined logical data type as UTF-8 text
binary_formatOptionalString: HEX, BASE64, UTF8Encoding format for binary input or output
compressionOptionalString/null: AUTO, GZIP, BZ2, BROTLI, ZSTD, DEFLATE, RAW_DEFLATE, NONESpecifies the current compression algorithm for the data file
date_formatOptionalStringFormat of the date values in the data files to load
disable_auto_convertOptionalBooleanSpecifies whether the XML parser disables automatic conversion of numeric and Boolean values from text to native representation
disable_snowflake_dataOptionalBooleanSpecifies whether the XML parser disables recognition of Snowflake semi-structured data tags
empty_field_as_nullOptionalBooleanSpecifies whether to insert SQL NULL for empty fields in an input file, which are represented by two successive delimiters
enable_OCTALOptionalBooleanEnables parsing of octal numbers
encodingOptionalStringSpecifies the character set of the source data when loading it into a table
error_on_column_count_mismatchOptionalBooleanSpecifies whether to generate a parsing error if the number of delimited columns (i.e. fields) in an input file does not match the number of columns in the corresponding table
escapeOptionalString/nullCharacter used as the escape character for enclosed field values
escape_unenclosed_fieldOptionalString/nullCharacter used as the escape character for unenclosed field values
field_delimiterOptionalString/nullCharacters that separate fields in an input file
field_optionally_enclosed_byOptionalString/nullCharacter used to enclose strings
ignore_utf8_errorsOptionalBooleanSpecifies whether UTF-8 encoding errors produce error conditions
null_ifOptionalStringConverts to and from SQL NULL
preserve_spaceOptionalBooleanSpecifies whether the XML parser preserves leading and trailing spaces in element content
record_delimiterOptionalString/nullCharacters that separate records in an input file
replace_invalid_charactersOptionalBooleanSpecifies whether to replace invalid UTF-8 characters with the Unicode replacement character
skip_blank_linesOptionalBooleanSpecifies to skip any blank lines encountered in the data files
skip_byte_order_markOptionalBooleanSpecifies whether to skip the BOM (byte order mark) if present in a data file
skip_headerOptionalIntegerNumber of lines at the start of the file to skip
strip_null_valuesOptionalBooleanTells the JSON parser to remove object fields or array elements containing null values
strip_outer_arrayOptionalBooleanTells the JSON parser to remove outer brackets
strip_outer_elementOptionalBooleanSpecifies whether the XML parser strips out the outer XML element, exposing 2nd level elements as separate documents
time_formatOptionalStringFormat of the time values in the data files to load
timestamp_formatOptionalStringFormat of the timestamp values in the data files to load
trim_spaceOptionalBooleanSpecifies whether to remove white space from fields
validate_utf8OptionalBooleanSpecifies whether to validate UTF-8 character encoding in string column data. Caution: This parameter only supports TRUE as a value. Using FALSE would result in compiler failure. This is due to the fact FALSE value has been made obsolete by Snowflake as of release 2022_03.

Unsupported copy option parameters for pipe

All COPY INTO table copy options are supported except for the following:

  • files
  • on_error
  • size_limit
  • purge
  • force
  • return_failed_only
  • validation_mode
  • load_uncertain_files