CREATE EXTERNAL TABLE

statementpartialIceberg & external tables

docs.snowflake.com ↗

Object: EXTERNAL TABLE

Creates a new external table in the current or specified schema or replaces an existing external table. When queried, an external table reads data from a set of one or more files in a specified external stage, and then outputs the data in a single VARIANT column. Additional columns can be defined, with each column definition consisting of a name, data type, and optionally whether the column requires a value (NOT NULL) or has any referential integrity constraints (such as primary key, foreign key). For more information, see the usage notes.

Syntax

supportedpartialnot supportednot scored

-- Partitions computed from expressions
CREATE [ OR REPLACE ] EXTERNAL TABLE [IF NOT EXISTS]
  <table_name>
    ( [ <col_name> <col_type> AS <expr> | <part_col_name> <col_type> AS <part_expr> ]
      [ inlineConstraint ]
      [ , <col_name> <col_type> AS <expr> | <part_col_name> <col_type> AS <part_expr> ... ]
      [ , ... ] )
  cloudProviderParams
  [ PARTITION BY ( <part_col_name> [, <part_col_name> ... ] ) ]
  [ WITH ] LOCATION = externalStage
  [ REFRESH_ON_CREATE =  { TRUE | FALSE } ]
  [ AUTO_REFRESH = { TRUE | FALSE } ]
  [ PATTERN = '<regex_pattern>' ]
  FILE_FORMAT = ( { FORMAT_NAME = '<file_format_name>' | TYPE = { CSV | JSON | AVRO | ORC | PARQUET } [ formatTypeOptions ] } )
  [ AWS_SNS_TOPIC = '<string>' ]
  [ COPY GRANTS ]
  [ COPY = ( GRANTS ) ]
  [ COMMENT = '<string_literal>' ]
  [ [ WITH ] ROW ACCESS POLICY <policy_name> ON (VALUE) ]
  [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
  [ WITH CONTACT ( <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ) ]

-- Partitions added and removed manually
CREATE [ OR REPLACE ] EXTERNAL TABLE [IF NOT EXISTS]
  <table_name>
    ( [ <col_name> <col_type> AS <expr> | <part_col_name> <col_type> AS <part_expr> ]
      [ inlineConstraint ]
      [ , <col_name> <col_type> AS <expr> | <part_col_name> <col_type> AS <part_expr> ... ]
      [ , ... ] )
  cloudProviderParams
  [ PARTITION BY ( <part_col_name> [, <part_col_name> ... ] ) ]
  [ WITH ] LOCATION = externalStage
  PARTITION_TYPE = USER_SPECIFIED
  FILE_FORMAT = ( { FORMAT_NAME = '<file_format_name>' | TYPE = { CSV | JSON | AVRO | ORC | PARQUET } [ formatTypeOptions ] } )
  [ COPY GRANTS ]
  [ COPY = ( GRANTS ) ]
  [ COMMENT = '<string_literal>' ]
  [ [ WITH ] ROW ACCESS POLICY <policy_name> ON (VALUE) ]
  [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
  [ WITH CONTACT ( <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ) ]

-- Delta Lake
CREATE [ OR REPLACE ] EXTERNAL TABLE [IF NOT EXISTS]
  <table_name>
    ( [ <col_name> <col_type> AS <expr> | <part_col_name> <col_type> AS <part_expr> ]
      [ inlineConstraint ]
      [ , <col_name> <col_type> AS <expr> | <part_col_name> <col_type> AS <part_expr> ... ]
      [ , ... ] )
  cloudProviderParams
  [ PARTITION BY ( <part_col_name> [, <part_col_name> ... ] ) ]
  [ WITH ] LOCATION = externalStage
  PARTITION_TYPE = USER_SPECIFIED
  FILE_FORMAT = ( { FORMAT_NAME = '<file_format_name>' | TYPE = { CSV | JSON | AVRO | ORC | PARQUET } [ formatTypeOptions ] } )
  [ TABLE_FORMAT = DELTA ]
  [ COPY GRANTS ]
  [ COPY = ( GRANTS ) ]
  [ COMMENT = '<string_literal>' ]
  [ [ WITH ] ROW ACCESS POLICY <policy_name> ON (VALUE) ]
  [ [ WITH ] TAG ( <tag_name> = '<tag_value>' [ , <tag_name> = '<tag_value>' , ... ] ) ]
  [ WITH CONTACT ( <purpose> = <contact_name> [ , <purpose> = <contact_name> ... ] ) ]

Where

inlineConstraint ::=
  [ NOT NULL ]
  [ CONSTRAINT <constraint_name> ]
  { UNIQUE | PRIMARY KEY | [ FOREIGN KEY ] REFERENCES <ref_table_name> [ ( <ref_col_name> [ , <ref_col_name> ] ) ] }
  [ <constraint_properties> ]

For additional inline constraint details, see CREATE | ALTER TABLE … CONSTRAINT.

cloudProviderParams (for Google Cloud Storage) ::=
  [ INTEGRATION = '<integration_name>' ]

cloudProviderParams (for Microsoft Azure) ::=
  [ INTEGRATION = '<integration_name>' ]

For additional inline constraint details, see CREATE | ALTER TABLE … CONSTRAINT.

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

For additional inline constraint details, see CREATE | ALTER TABLE … CONSTRAINT.

formatTypeOptions ::=
-- If FILE_FORMAT = ( TYPE = CSV ... )
     COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONE
     RECORD_DELIMITER = '<string>' | NONE
     FIELD_DELIMITER = '<string>' | NONE
     MULTI_LINE = TRUE | FALSE
     SKIP_HEADER = <integer>
     SKIP_BLANK_LINES = TRUE | FALSE
     ESCAPE_UNENCLOSED_FIELD = '<character>' | NONE
     TRIM_SPACE = TRUE | FALSE
     FIELD_OPTIONALLY_ENCLOSED_BY = '<character>' | NONE
     NULL_IF = ( '<string1>' [ , '<string2>' , ... ] )
     EMPTY_FIELD_AS_NULL = TRUE | FALSE
     ENCODING = '<string>'
-- If FILE_FORMAT = ( TYPE = JSON ... )
     COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONE
     MULTI_LINE = TRUE | FALSE
     ALLOW_DUPLICATE = TRUE | FALSE
     STRIP_OUTER_ARRAY = TRUE | FALSE
     STRIP_NULL_VALUES = TRUE | FALSE
     REPLACE_INVALID_CHARACTERS = TRUE | FALSE
-- If FILE_FORMAT = ( TYPE = AVRO ... )
     COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONE
     REPLACE_INVALID_CHARACTERS = TRUE | FALSE
-- If FILE_FORMAT = ( TYPE = ORC ... )
     TRIM_SPACE = TRUE | FALSE
     REPLACE_INVALID_CHARACTERS = TRUE | FALSE
     NULL_IF = ( '<string>' [ , '<string>' ... ]
-- If FILE_FORMAT = ( TYPE = PARQUET ... )
     COMPRESSION = AUTO | SNAPPY | NONE
     BINARY_AS_TEXT = TRUE | FALSE
     REPLACE_INVALID_CHARACTERS = TRUE | FALSE

Creates a new external table with the column definitions derived from a set of staged files that contain semi-structured data. This feature supports Apache Parquet, Apache Avro, ORC, JSON, and CSV files. The support for CSV and JSON files is currently in preview.

CREATE [ OR REPLACE ] EXTERNAL TABLE <table_name>
  USING TEMPLATE <query>
  [ ... ]
  [ COPY GRANTS ]
  [ COPY = ( GRANTS ) ]

Parameters

NameRequiredDescription
table_namerequiredString that specifies the identifier (that is, name) for the table; must be unique for the schema in which the table is created. In addition, the identifier must start with an alphabetic character and can’t contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case sensitive. For more information, see Identifier requirements.
[ WITH ] LOCATION =requiredSpecifies the external stage and optional path where the files containing data to be read are staged: @[namespace.]ext_stage_name[/path] Files are in the specified named external stage.ExpandShow lessSee more Neither string literals nor SQL variables are supported. Where: <namespace> is the database or schema in which the external stage 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. <path> is an optional case-sensitive directory path for files in the cloud storage location that limits the set of files to load. Paths are alternatively called prefixes or folders by different cloud storage services. The external table appends this directory path to any path specified in the stage definition. To view the stage definition, run DESC STAGE stage_name and check the url property value. For example, if the stage URL includes path a and the external table location includes path b, then the external table reads files staged in <stage>/a/b. Note Specify a full directory path, and not a partial path (shared prefix) for files in your storage location (for example, use a path like @my_ext_stage/2025/ instead of @my_ext_stage/2025-*). To filter for files that share a common prefix, use partition columns instead. The [ WITH ] LOCATION value cannot reference specific file names. To point an external table to individual staged files, use the PATTERN parameter.
FILE_FORMAT = ( FORMAT_NAME = 'file_format_name' ) or FILE_FORMAT = ( TYPE = CSV | JSON | AVRO | ORC | PARQUET [ ... ] )requiredString (constant) that specifies the file format: Default: TYPE = CSV. Important An external table doesn’t inherit FILE_FORMAT options specified in a stage definition when that stage is used for loading data into the table. To specify FILE_FORMAT options, you must explicitly do so in the external table definition. Snowflake uses defaults for any FILE_FORMAT parameters omitted from the external table definition. Note FORMAT_NAME and TYPE are mutually exclusive; to avoid unintended behavior, only specify one or the other when you create an external table.
FORMAT_NAME = file_format_nameSpecifies an existing named file format that describes the staged data files to scan. The named file format determines the format type (such as, CSV, JSON), and any other format options, for data files.
TYPE = CSV | JSON | AVRO | ORC | PARQUET [ ... ]Specifies the format type of the staged data files to scan when querying the external table. If a file format type is specified, additional format-specific options can be specified. For more information, see Format Type Options in this topic.
col_nameoptionalString that specifies the column identifier (that is, name). All the requirements for table identifiers also apply to column identifiers. For more information, see Identifier requirements.
col_typeoptionalString (constant) that specifies the data type for the column. The data type must match the result of expr for the column. For information about the data types that can be specified for table columns, see SQL data types reference.
exproptionalString that specifies the expression for the column. When queried, the column returns results derived from this expression. External table columns are virtual columns, which are defined by using an explicit expression. Add virtual columns as expressions by using the VALUE column or the METADATA$FILENAME pseudocolumn: VALUE: A VARIANT type column that represents a single row in the external file. CSV: The VALUE column structures each row as an object with elements identified by column position (that is, {c1: <column_1_value>, c2: <column_2_value>, c3: <column_1_value> ...}). For example, add a VARCHAR column named mycol that references the first column in the staged CSV files:Copy code mycol varchar as (value:c1::varchar) Semi-structured data: Enclose element names and values in double-quotes. Traverse the path in the VALUE column by using dot notation. Suppose the following example represents a single row of semi-structured data in a staged file:Copy code { "a":"1", "b": { "c":"2", "d":"3" } } Add a VARCHAR column named mycol that references the nested repeating c element in the staged file:Copy code mycol varchar as (value:"b"."c"::varchar) METADATA$FILENAME: A pseudocolumn that identifies the name of each staged data file that is included in the external table, including its path in the stage. For an example, see Partitions Added Automatically From Partition Column Expressions in this topic.
CONSTRAINT ...optionalString that defines an inline or out-of-line constraint for the specified columns in the table. For syntax details, see CREATE | ALTER TABLE … CONSTRAINT. For more information about constraints, see Constraints.
REFRESH_ON_CREATE = { TRUE | FALSE }optionalSpecifies whether to automatically refresh the external table metadata one time, immediately after the external table is created. Refreshing the external table metadata synchronizes the metadata with the current list of data files in the specified stage path. This action is required for the metadata to register any existing data files in the named external stage specified in the [ WITH ] LOCATION = setting. Default: TRUE
  • TRUE — Snowflake automatically refreshes the external table metadata one time after creation. Note If the specified location contains close to 1 million files or more, we recommend that you set REFRESH_ON_CREATE = FALSE. After you create the external table, refresh the metadata incrementally by running ALTER EXTERNAL TABLE … REFRESH statements that specify subpaths in the location (that is, subsets of files to include in the refresh) until the metadata includes all of the files in the location.
  • FALSE — Snowflake doesn’t automatically refresh the external table metadata. To register any existing data files in the stage, you must manually refresh the external table metadata one time by using ALTER EXTERNAL TABLE … REFRESH.
AUTO_REFRESH = { TRUE | FALSE }optionalSpecifies whether Snowflake should enable triggering automatic refreshes of the external table metadata when new or updated data files are available in the named external stage specified in the [ WITH ] LOCATION = setting. Note Setting this parameter to TRUE isn’t supported by partitioned external tables when partitions are added manually by the object owner (that is, when PARTITION_TYPE = USER_SPECIFIED). Setting this parameter to TRUE isn’t supported for external tables that reference data files in S3-compatible storage (a storage application or device that provides an API compliant with the S3 REST API). For more information, see Work with Amazon S3-compatible storage. You must manually refresh the metadata by running an ALTER EXTERNAL TABLE … REFRESH command. Amazon S3: Refresh external tables automatically for Amazon S3 Google Cloud Storage: Refresh external tables automatically for Google Cloud Storage Microsoft Azure: Refresh external tables automatically for Azure Blob Storage When an external table is created, its metadata is refreshed automatically one time unless REFRESH_ON_CREATE = FALSE. Default: TRUE
  • TRUE — Snowflake enables triggering automatic refreshes of the external table metadata.
  • FALSE — Snowflake doesn’t enable triggering automatic refreshes of the external table metadata. You must manually refresh the external table metadata periodically by using ALTER EXTERNAL TABLE … REFRESH to synchronize the metadata with the current list of files in the stage path.
PATTERN = 'regex_pattern'optionalA regular expression pattern string, enclosed in single quotes, specifying the filenames and paths on the external stage to match. Tip For the best performance, don’t apply patterns that filter on a large number of files.
AWS_SNS_TOPIC = 'string'optionalRequired only when configuring AUTO_REFRESH for Amazon S3 stages using Amazon Simple Notification Service (SNS). Specifies the Amazon Resource Name (ARN) for the SNS topic for your S3 bucket. The CREATE EXTERNAL TABLE statement subscribes the Amazon Simple Queue Service (SQS) queue to the specified SNS topic. Event notifications through the SNS topic trigger metadata refreshes. For more information, see Refresh external tables automatically for Amazon S3.
COPY GRANTSoptionalSpecifies retaining the access permissions from the original table when an external table is recreated using the CREATE OR REPLACE TABLE variant. The parameter copies all permissions, except OWNERSHIP, from the existing table to the new table. By default, the role that runs the CREATE EXTERNAL TABLE command owns the new external table. Note The operation to copy grants occurs atomically in the CREATE EXTERNAL TABLE command (that is, within the same transaction). You can also copy grants with the COPY = ( GRANTS ) parameter. For external tables, COPY = ( ... ) accepts only GRANTS.
COMMENT = 'string_literal'optionalString (literal) that specifies a comment for the external table. Default: No value
ROW ACCESS POLICY <policy_name> ON (VALUE)optionalSpecifies the row access policy to set on the table. Specify the VALUE column when applying a row access policy to an external table.
WITH DATA METRIC FUNCTION ( dmf_name ON ( col_name [ , col_name ... ] ) [ , dmf_binding ... ] )optionalAssociates one or more data metric functions (DMFs) with the external table at creation time. The DMF begins running on the schedule configured for the table as soon as it is created. You can attach multiple DMF bindings by separating them with commas. Each binding accepts the same properties as ALTER TABLE … ADD DATA METRIC FUNCTION, including EXECUTE AS ROLE, ANOMALY_DETECTION, SENSITIVITY, DATA_QUALITY_NOTIFICATION, and EXPECTATION. For a description of each property, see Data metric function actions. Snowflake also accepts this clause without the parentheses around the binding list, but that form is deprecated and a future behavior change release removes it. For usage guidance and examples, see Attach DMFs at creation time. Default: No value (no DMF is associated with the external table)
TAG ( tag_name = 'tag_value' [ , tag_name = 'tag_value' , ... ] )optionalSpecifies the tag name and the tag string value. The tag value is always a string, and the maximum number of characters for the tag value is 256. For information about specifying tags in a statement, see Tag quotas.
WITH CONTACT ( purpose = contact [ , purpose = contact ...] )optionalAssociate the new object with one or more contacts. Specify the WITH CONTACT clause after all other clauses except the AS clause (if that clause is supported by this command).
part_col_name col_type AS part_exproptionalDefines one or more partition columns in the external table. The format of a partition column definition differs depending on whether partitions are computed and added automatically from an expression in each partition column or the partitions are added manually. Added from an expression: A partition column must evaluate as an expression that parses the path or filename information in the METADATA$FILENAME pseudocolumn. Partition columns optimize query performance by pruning out the data files that don’t need to be scanned (that is, partitioning the external table). A partition consists of all data files that match the path or filename in the expression for the partition column.
PARTITION_TYPE = USER_SPECIFIEDoptionalDefines the partition type for the external table as user-defined. The owner of the external table (that is, the role that has the OWNERSHIP privilege on the external table) must add partitions to the external metadata manually by running ALTER EXTERNAL TABLE … ADD PARTITION statements. Don’t set this parameter if partitions are added to the external table metadata automatically upon evaluation of expressions in the partition columns.
[ PARTITION BY ( part_col_name [, part_col_name ... ] ) ]optionalSpecifies any partition columns to evaluate for the external table. Usage: When you query an external table, include one or more partition columns in a WHERE clause; for example:... WHERE part_col_name = 'filter_value' Snowflake filters on the partition columns to restrict the set of data files to scan. All rows in these files are scanned. If a WHERE clause includes non-partition columns, those filters are evaluated after the data files are filtered. A common practice is to partition the data files based on increments of time; or, if the data files are staged from multiple sources, to partition by a data source identifier and date or timestamp.
INTEGRATION = integration_nameSpecifies the name of the notification integration used to automatically refresh the external table metadata using Google Pub/Sub event notifications. A notification integration is a Snowflake object that provides an interface between Snowflake and third-party cloud message queuing services. This parameter is required to enable auto-refresh operations for the external table. For instructions about how to configure the auto-refresh capability, see Refresh external tables automatically for Google Cloud Storage.
INTEGRATION = integration_nameSpecifies the name of the notification integration used to automatically refresh the external table metadata using Azure Event Grid notifications. A notification integration is a Snowflake object that provides an interface between Snowflake and third-party cloud message queuing services. This parameter is required to enable auto-refresh operations for the external table. For instructions about how to configure the auto-refresh capability, see Refresh external tables automatically for Azure Blob Storage.
COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONEString (constant) that specifies the current compression algorithm for the data files to be queried. Snowflake uses this option to detect how already-compressed data files were compressed so that the compressed data in the files can be extracted for querying. Supported Values Notes AUTO Compression algorithm detected automatically, except for Brotli-compressed files, which cannot currently be detected automatically. If querying Brotli-compressed files, explicitly use BROTLI instead of AUTO. GZIP BZ2 BROTLI Must be specified when querying Brotli-compressed files. ZSTD Zstandard v0.8 (and higher) supported. DEFLATE Deflate-compressed files (with zlib header, RFC1950). RAW_DEFLATE Raw Deflate-compressed files (without header, RFC1951). NONE Data files have not been compressed.ExpandShow lessSee more
RECORD_DELIMITER = 'string' | NONEOne or more characters that separate records in an input 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 input 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. 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: comma (,)
MULTI_LINE = TRUE | FALSEBoolean that specifies whether multiple lines are allowed. If MULTI_LINE is set to FALSE and the specified record delimiter is present within a CSV field, the record containing the field will be interpreted as an error. Default: TRUE
SKIP_HEADER = integerNumber of lines at the start of the file to skip. Note that SKIP_HEADER does not use the RECORD_DELIMITER or FIELD_DELIMITER values to determine what a header line is; rather, it simply skips the specified number of CRLF (Carriage Return, Line Feed)-delimited lines in the file. RECORD_DELIMITER and FIELD_DELIMITER are then used to determine the rows of data to query. Default: 0
SKIP_BLANK_LINES = TRUE | FALSEUse: Data querying only Definition: Boolean that specifies to skip any blank lines encountered in the data files; otherwise, blank lines produce an end-of-record error (default behavior). Default: FALSE
ESCAPE_UNENCLOSED_FIELD = 'character' | NONEA 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. Specifies the escape character for unenclosed fields only. Note The default value is \\. If a row in a data file ends in the backslash (\) character, this character escapes the newline or carriage return character specified for the RECORD_DELIMITER file format option. As a result, this row and the next row are handled as a single row of data. To avoid this issue, set the value to NONE. This file format option supports singlebyte characters only. Note that UTF-8 character encoding represents high-order ASCII characters as multibyte characters. If your data file is encoded with the UTF-8 character set, you cannot specify a high-order ASCII character as the option value. In addition, if you specify a high-order ASCII character, we recommend that you set the ENCODING = 'string' file format option as the character encoding for your data files to ensure the character is interpreted correctly. Default: backslash (\\)
TRIM_SPACE = TRUE | FALSEBoolean that specifies whether to remove white space from fields. For example, if your external database software encloses fields in quotes, but inserts a leading space, Snowflake reads the leading space rather than the opening quotation character as the beginning of the field (that is, the quotation marks are interpreted as part of the string of field data). Set this option to TRUE to remove undesirable spaces when querying data. As another example, if leading or trailing spaces surround quotes that enclose strings, you can remove the surrounding spaces using this option and the quote character using the FIELD_OPTIONALLY_ENCLOSED_BY option. Note that any spaces within the quotes are preserved. For example, assuming FIELD_DELIMITER = '|' and FIELD_OPTIONALLY_ENCLOSED_BY = '"':Copy code |"Hello world"| /* returned as */ >Hello world< |" Hello world "| /* returned as */ > Hello world < | "Hello world" | /* returned as */ >Hello world< Note that the brackets in this example are not returned; they are used to demarcate the beginning and end of the returned strings. Default: FALSE
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 (''). Default: NONE
NULL_IF = ( 'string1' [ , 'string2' , ... ] )String used to convert to and from SQL NULL: When querying data, Snowflake replaces these values in the returned data with SQL NULL. To specify more than one string, enclose the list of strings in parentheses and use commas to separate each value. Note that Snowflake converts all instances of the value to NULL, regardless of the data type. For example, if 2 is specified as a value, all instances of 2 as either a string or number are converted. For example: NULL_IF = ('\N', 'NULL', 'NUL', '') Note that this option can include empty strings. Default: \N (that is, NULL, which assumes the ESCAPE_UNENCLOSED_FIELD value is \\)
EMPTY_FIELD_AS_NULL = TRUE | FALSESpecifies whether to return SQL NULL for empty fields in an input file, which are represented by two successive delimiters (e.g. ,,). If set to FALSE, Snowflake attempts to cast an empty field to the corresponding column type. An empty string is returned for columns of type STRING. For other column types, the query returns an error. Default: TRUE
ENCODING = 'string'String (constant) that specifies the character set of the source data when querying data. Character Set ENCODING Value Supported Languages Notes Big5 BIG5 Traditional Chinese EUC-JP EUCJP Japanese EUC-KR EUCKR Korean GB18030 GB18030 Chinese IBM420 IBM420 Arabic IBM424 IBM424 Hebrew IBM949 IBM949 Korean ISO-2022-CN ISO2022CN Simplified Chinese ISO-2022-JP ISO2022JP Japanese ISO-2022-KR ISO2022KR Korean ISO-8859-1 ISO88591 Danish, Dutch, English, French, German, Italian, Norwegian, Portuguese, Swedish ISO-8859-2 ISO88592 Czech, Hungarian, Polish, Romanian ISO-8859-5 ISO88595 Russian ISO-8859-6 ISO88596 Arabic ISO-8859-7 ISO88597 Greek ISO-8859-8 ISO88598 Hebrew ISO-8859-9 ISO88599 Turkish ISO-8859-15 ISO885915 Danish, Dutch, English, French, German, Italian, Norwegian, Portuguese, Swedish Identical to ISO-8859-1 except for 8 characters, including the Euro currency symbol. KOI8-R KOI8R Russian Shift_JIS SHIFTJIS Japanese UTF-8 UTF8 All languages For loading data from delimited files (CSV, TSV, etc.), UTF-8 is the default. For loading data from all other supported file formats (JSON, Avro, etc.), as well as unloading data, UTF-8 is the only supported character set. UTF-16 UTF16 All languages UTF-16BE UTF16BE All languages UTF-16LE UTF16LE All languages UTF-32 UTF32 All languages UTF-32BE UTF32BE All languages UTF-32LE UTF32LE All languages windows-874 WINDOWS874 Thai windows-949 WINDOWS949 Korean windows-1250 WINDOWS1250 Czech, Hungarian, Polish, Romanian windows-1251 WINDOWS1251 Russian windows-1252 WINDOWS1252 Danish, Dutch, English, French, German, Italian, Norwegian, Portuguese, Swedish windows-1253 WINDOWS1253 Greek windows-1254 WINDOWS1254 Turkish windows-1255 WINDOWS1255 Hebrew windows-1256 WINDOWS1256 Arabic ExpandShow lessSee more Default: UTF8 Note Snowflake stores all data internally in the UTF-8 character set. The data is converted into UTF-8.
COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONEString (constant) that specifies the current compression algorithm for the data files to be returned. Snowflake uses this option to detect how already-compressed data files were compressed so that the compressed data in the files can be extracted for querying. Supported Values Notes AUTO Compression algorithm detected automatically, except for Brotli-compressed files, which cannot currently be detected automatically. If querying Brotli-compressed files, explicitly use BROTLI instead of AUTO. GZIP BZ2 BROTLI ZSTD DEFLATE Deflate-compressed files (with zlib header, RFC1950). RAW_DEFLATE Raw Deflate-compressed files (without header, RFC1951). NONE Indicates the files have not been compressed.ExpandShow lessSee more Default: AUTO
MULTI_LINE = TRUE | FALSEBoolean that specifies whether multiple lines are allowed. If MULTI_LINE is set to FALSE and a new line is present within a JSON record, the record containing the new line will be interpreted as an error. Default: TRUE
ALLOW_DUPLICATE = TRUE | FALSEBoolean that specifies to allow duplicate object field names (only the last one will be preserved). Default: FALSE
STRIP_OUTER_ARRAY = TRUE | FALSEBoolean that instructs the JSON parser to remove outer brackets (that is, [ ]). Default: FALSE
STRIP_NULL_VALUES = TRUE | FALSEBoolean that instructs the JSON parser to remove object fields or array elements containing null values. For example, when set to TRUE: Before After [null] [] [null,null,3] [,,3] {"a":null,"b":null,"c":123} {"c":123} {"a":[1,null,2],"b":{"x":null,"y":88}} {"a":[1,,2],"b":{"y":88}}ExpandShow lessSee more Default: FALSE
REPLACE_INVALID_CHARACTERS = TRUE | FALSEBoolean that specifies whether to replace invalid UTF-8 characters with the Unicode replacement character (�). This option performs a one-to-one character replacement. If set to TRUE, Snowflake replaces invalid UTF-8 characters with the Unicode replacement character. If set to FALSE, the load operation produces an error when invalid UTF-8 character encoding is detected. Default: FALSE
COMPRESSION = AUTO | GZIP | BZ2 | BROTLI | ZSTD | DEFLATE | RAW_DEFLATE | NONEString (constant) that specifies the current compression algorithm for the data files to be queried. Snowflake uses this option to detect how already-compressed data files were compressed so that the compressed data in the files can be extracted for querying. Supported Values Notes AUTO Compression algorithm detected automatically, except for Brotli-compressed files, which cannot currently be detected automatically. If querying Brotli-compressed files, explicitly use BROTLI instead of AUTO. GZIP BZ2 BROTLI ZSTD DEFLATE Deflate-compressed files (with zlib header, RFC1950). RAW_DEFLATE Raw Deflate-compressed files (without header, RFC1951). NONE Data files to query have not been compressed.ExpandShow lessSee more Default: AUTO.
REPLACE_INVALID_CHARACTERS = TRUE | FALSEBoolean that specifies whether to replace invalid UTF-8 characters with the Unicode replacement character (�). This option performs a one-to-one character replacement. If set to TRUE, Snowflake replaces invalid UTF-8 characters with the Unicode replacement character. If set to FALSE, the load operation produces an error when invalid UTF-8 character encoding is detected. Default: FALSE
TRIM_SPACE = TRUE | FALSEBoolean that specifies whether to remove leading and trailing white space from strings. For example, if your external database software encloses fields in quotes, but inserts a leading space, Snowflake reads the leading space rather than the opening quotation character as the beginning of the field (that is, the quotation marks are interpreted as part of the string of field data). Set this option to TRUE to remove undesirable spaces. This file format option is applied to the following actions only: Querying object values in staged ORC data files. Querying ORC data in separate columns using the MATCH_BY_COLUMN_NAME copy option. Querying ORC data in separate columns by specifying a query in the COPY statement (that is, COPY transformation). Default: FALSE
REPLACE_INVALID_CHARACTERS = TRUE | FALSEBoolean that specifies whether to replace invalid UTF-8 characters with the Unicode replacement character (�). This option performs a one-to-one character replacement. If set to TRUE, Snowflake replaces invalid UTF-8 characters with the Unicode replacement character. If set to FALSE, the load operation produces an error when invalid UTF-8 character encoding is detected. Default: FALSE
NULL_IF = ( 'string1' [ , 'string2' , ... ] )String used to convert to and from SQL NULL. Snowflake replaces these strings in the data source with SQL NULL. To specify more than one string, enclose the list of strings in parentheses and use commas to separate each value. Note that Snowflake converts all instances of the value to NULL, regardless of the data type. For example, if 2 is specified as a value, all instances of 2 as either a string or number are converted. For example: NULL_IF = ('\N', 'NULL', 'NUL', '') Note that this option can include empty strings. This file format option is applied when querying object values in staged ORC data files. Default: \N (that is, NULL)
COMPRESSION = AUTO | SNAPPY | NONEString (constant) that specifies the current compression algorithm for columns in the Parquet files. Supported Values Notes AUTO Compression algorithm detected automatically. Supports the following compression algorithms: Brotli, gzip, Lempel-Ziv-Oberhumer (LZO), LZ4, Snappy, or Zstandard v0.8 (and higher). SNAPPY NONE Data files have not been compressed.ExpandShow lessSee more Default: AUTO
BINARY_AS_TEXT = TRUE | FALSEBoolean that specifies whether to interpret columns with no defined logical data type as UTF-8 text. When set to FALSE, Snowflake interprets these columns as binary data. Default: TRUE Note Snowflake recommends that you set BINARY_AS_TEXT to FALSE to avoid any potential conversion issues.
REPLACE_INVALID_CHARACTERS = TRUE | FALSEBoolean that specifies whether to replace invalid UTF-8 characters with the Unicode replacement character (�). This option performs a one-to-one character replacement. If set to TRUE, Snowflake replaces invalid UTF-8 characters with the Unicode replacement character. If set to FALSE, the load operation produces an error when invalid UTF-8 character encoding is detected. Default: FALSE

Usage notes

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE EXTERNAL TABLE | Schema | CREATE STAGE | Schema | Required if creating a new stage. USAGE | Stage | Required if referencing an existing stage. USAGE | File format | 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.

Known gaps

Parts not fully supported, and recorded divergences from Snowflake.

See also

Referenced by