Skip to content

Commit 714aace

Browse files
Several updates to update the current behavior of COPY INTO
1 parent 9522587 commit 714aace

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

docs/t-sql/statements/copy-into-transact-sql.md

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Use COPY for the following capabilities:
3737
- Specify a finer permission model without exposing storage account keys using Share Access Signatures (SAS)
3838
- Use a different storage account for the ERRORFILE location (REJECTED_ROW_LOCATION)
3939
- Customize default values for each target column and specify source data fields to load into specific target columns
40-
- Specify a custom row terminator for CSV files
40+
- Specify a custom row terminator, field terminator, and field quote for CSV files
4141
- Use SQL Server Date formats for CSV files
4242
- Specify wildcards and multiple files in the storage location path
4343
- Automatic schema discovery simplifies the process of defining and mapping source data into target tables
@@ -79,7 +79,7 @@ WITH
7979

8080
#### *schema_name*
8181

82-
Optional if the default schema for the user performing the operation is the schema of the specified table. If *schema* isn't specified, and the default schema of the user performing the COPY operation is different from the specified table, COPY is canceled, and an error message is returned.
82+
Optional if the default schema for the user performing the operation is the schema of the specified table. If *schema* isn't specified, and the default schema of the user performing the COPY operation is different from the schema of the specified table, COPY is canceled, and an error message is returned.
8383

8484
#### *table_name*
8585

@@ -97,7 +97,7 @@ Don't specify a *column_list* when `AUTO_CREATE_TABLE = 'ON'`.
9797

9898
- *Column_name* - the name of the column in the target table.
9999
- *Default_value* - the default value that replaces any NULL value in the input file. Default value applies to all file formats. COPY attempts to load NULL from the input file when a column is omitted from the column list or when there's an empty input file field. Default value precedes the keyword 'default'
100-
- *Field_number* - the input file field number that is mapped to the target column name.
100+
- *Field_number* - the input file field number that is mapped to the target column.
101101
- The field indexing starts at 1.
102102

103103
When a column list isn't specified, COPY maps columns based on the source and target order: Input field 1 goes to target column 1, field 2 goes to column 2, etc.
@@ -195,9 +195,12 @@ Multiple file locations can only be specified from the same storage account and
195195

196196
*ERRORFILE* only applies to CSV. Specifies the directory within the COPY statement where the rejected rows and the corresponding error file should be written. The full path from the storage account can be specified or the path relative to the container can be specified. If the specified path doesn't exist, one is created on your behalf. A child directory is created with the name "\_rejectedrows". The "\_" character ensures that the directory is escaped for other data processing unless explicitly named in the location parameter.
197197

198+
> [!NOTE]
199+
> When a relative path is passed to *ERRORFILE*, the path is relative to the container path specified in *external_location*.
200+
198201
Within this directory, there's a folder created based on the time of load submission in the format YearMonthDay -HourMinuteSecond (Ex. 20180330-173205). In this folder, two types of files are written, the reason (Error) file and the data (Row) file each preappending with the queryID, distributionID, and a file guid. Because the data and the reason are in separate files, corresponding files have a matching prefix.
199202

200-
If ERRORFILE has the full path of the storage account defined, then the ERRORFILE_CREDENTIAL is used to connect to that storage. Otherwise, the value mentioned for CREDENTIAL is used.
203+
If ERRORFILE has the full path of the storage account defined, then the ERRORFILE_CREDENTIAL is used to connect to that storage. Otherwise, the value mentioned for CREDENTIAL is used. When the same credential that is used for the source data is used for ERRORFILE, restrictions that apply to ERRORFILE_CREDENTIAL also apply
201204

202205
#### *ERRORFILE_CREDENTIAL = (IDENTITY= '', SECRET = '')*
203206

@@ -236,7 +239,7 @@ If ERRORFILE has the full path of the storage account defined, then the ERRORFIL
236239
237240
#### *MAXERRORS = max_errors*
238241

239-
*MAXERRORS* specifies the maximum number of reject rows allowed in the load before the COPY operation is canceled. Each row that can't be imported by the COPY operation is ignored and counted as one error. If max_errors isn't specified, the default is 0.
242+
*MAXERRORS* specifies the maximum number of reject rows allowed in the load before the COPY operation fails. Each row that can't be imported by the COPY operation is ignored and counted as one error. If max_errors isn't specified, the default is 0.
240243

241244
#### *COMPRESSION = { 'DefaultCodec ' | 'Snappy' | 'GZIP' | 'NONE'}*
242245

@@ -255,22 +258,22 @@ The COPY command autodetects the compression type based on the file extension wh
255258

256259
#### *FIELDQUOTE = 'field_quote'*
257260

258-
*FIELDQUOTE* applies to CSV and specifies a single character that is used as the quote character (string delimiter) in the CSV file. If not specified, the quote character (") is used as the quote character as defined in the RFC 4180 standard. Extended ASCII and multi-byte characters and aren't supported with UTF-8 for FIELDQUOTE.
261+
*FIELDQUOTE* applies to CSV and specifies a single character that is used as the quote character (string delimiter) in the CSV file. If not specified, the quote character (") is used as the quote character as defined in the RFC 4180 standard. Hexadecimal notation is also supported for FIELDQUOTE. Extended ASCII and multi-byte characters aren't supported with UTF-8 for FIELDQUOTE.
259262

260263
> [!NOTE]
261264
> FIELDQUOTE characters are escaped in string columns where there is a presence of a double FIELDQUOTE (delimiter).
262265
263266
#### *FIELDTERMINATOR = 'field_terminator'*
264267

265-
*FIELDTERMINATOR* Only applies to CSV. Specifies the field terminator that is used in the CSV file. The field terminator can be specified using hexadecimal notation. The field terminator can be multi-character. The default field terminator is a (,). Extended ASCII and multi-byte characters and aren't supported with UTF-8 for FIELDTERMINATOR.
268+
*FIELDTERMINATOR* Only applies to CSV. Specifies the field terminator that is used in the CSV file. The field terminator can be specified using hexadecimal notation. The field terminator can be multi-character. The default field terminator is a (,). Extended ASCII and multi-byte characters aren't supported with UTF-8 for FIELDTERMINATOR.
266269

267270
#### ROW TERMINATOR = 'row_terminator'
268271

269272
*ROW TERMINATOR* Only applies to CSV. Specifies the row terminator that is used in the CSV file. The row terminator can be specified using hexadecimal notation. The row terminator can be multi-character. By default, the row terminator is `\r\n`.
270273

271274
The COPY command prefixes the `\r` character when specifying `\n` (newline) resulting in `\r\n`. To specify only the `\n` character, use hexadecimal notation (`0x0A`). When specifying multi-character row terminators in hexadecimal, don't specify 0x between each character.
272275

273-
Extended ASCII and multi-byte characters and aren't supported with UTF-8 for ROW TERMINATOR.
276+
Extended ASCII and multi-byte characters aren't supported with UTF-8 for ROW TERMINATOR.
274277

275278
#### *FIRSTROW = First_row_int*
276279

@@ -354,7 +357,7 @@ The default values of the COPY command are:
354357

355358
- COMPRESSION default is uncompressed
356359

357-
- FIELDQUOTE = ''
360+
- FIELDQUOTE = '"'
358361

359362
- FIELDTERMINATOR = ','
360363

@@ -549,7 +552,7 @@ Use COPY for the following capabilities:
549552
- Specify a finer permission model without exposing storage account keys using Share Access Signatures (SAS).
550553
- Use a different storage account for the ERRORFILE location (REJECTED_ROW_LOCATION).
551554
- Customize default values for each target column and specify source data fields to load into specific target columns.
552-
- Specify a custom row terminator for CSV files.
555+
- Specify a custom row terminator, field terminator, and field quote for CSV files
553556
- Specify wildcards and multiple files in the storage location path.
554557
- For more on data ingestion options and best practices, see [Ingest data into your [!INCLUDE [fabricdw](../../includes/fabric-dw.md)] using the COPY statement](/fabric/data-warehouse/ingest-data-copy).
555558

@@ -584,7 +587,7 @@ Optional if the current warehouse for the user performing the operation is the w
584587

585588
#### *schema_name*
586589

587-
Optional if the default schema for the user performing the operation is the schema of the specified table. If *schema* isn't specified, and the default schema of the user performing the COPY operation is different from the specified table, COPY fails, and an error message is returned.
590+
Optional if the default schema for the user performing the operation is the schema of the specified table. If *schema* isn't specified, and the default schema of the user performing the COPY operation is different from the schema of the specified table, COPY is canceled, and an error message is returned.
588591

589592
#### *table_name*
590593

@@ -600,7 +603,7 @@ An optional list of one or more columns used to map source data fields to target
600603

601604
- *Column_name* - the name of the column in the target table.
602605
- *Default_value* - the default value that replaces any NULL value in the input file. Default value applies to all file formats. COPY attempts to load NULL from the input file when a column is omitted from the column list or when there's an empty input file field. Default value is preceded by the keyword 'default'
603-
- *Field_number* - applies only to CSV. The input file field number that is mapped to the target column name. For Parquet, columns are always bound by name.
606+
- *Field_number* - The input file field number that is mapped to the target column.
604607
- The field indexing starts at 1.
605608

606609
When *column_list* isn't specified, COPY maps columns based on the source and target order: Input field 1 goes to target column 1, field 2 goes to column 2, etc.
@@ -669,9 +672,12 @@ Multiple file locations can only be specified from the same storage account and
669672

670673
*ERRORFILE* only applies to CSV. Specifies the directory where the rejected rows and the corresponding error file should be written. The full path from the storage account can be specified or the path relative to the container can be specified. If the specified path doesn't exist, one is created on your behalf. A child directory is created with the name "\_rejectedrows". The "\_" character ensures that the directory is escaped for other data processing unless explicitly named in the location parameter.
671674

675+
> [!NOTE]
676+
> When a relative path is passed to *ERRORFILE*, the path is relative to the container path specified in *external_location*.
677+
672678
Within this directory, there's a folder created based on the time of load submission in the format YearMonthDay -HourMinuteSecond (Ex. 20180330-173205). In this folder a folder with the statement ID is created, and under that folder two types of files are written: an error.Json file containing the reject reasons, and a row.csv file containing the rejected rows.
673679

674-
If ERRORFILE has the full path of the storage account defined, then the ERRORFILE_CREDENTIAL is used to connect to that storage. Otherwise, the value mentioned for CREDENTIAL is used.
680+
If ERRORFILE has the full path of the storage account defined, then the ERRORFILE_CREDENTIAL is used to connect to that storage. Otherwise, the value mentioned for CREDENTIAL is used. When the same credential that is used for the source data is used for ERRORFILE, restrictions that apply to ERRORFILE_CREDENTIAL also apply.
675681

676682
#### *ERRORFILE_CREDENTIAL = (IDENTITY= '', SECRET = '')*
677683

@@ -687,7 +693,7 @@ If ERRORFILE has the full path of the storage account defined, then the ERRORFIL
687693
688694
#### *MAXERRORS = max_errors*
689695

690-
*MAXERRORS* specifies the maximum number of reject rows allowed in the load before the COPY operation is canceled. Each row that the COPY operation can't import is ignored and counted as one error. If max_errors isn't specified, the default is 0.
696+
*MAXERRORS* specifies the maximum number of reject rows allowed in the load before the COPY operation fails. Each row that the COPY operation can't import is ignored and counted as one error. If max_errors isn't specified, the default is 0.
691697

692698
#### *COMPRESSION = { 'Snappy' | 'GZIP' | 'NONE'}*
693699

@@ -702,22 +708,22 @@ The COPY command autodetects the compression type based on the file extension wh
702708

703709
#### *FIELDQUOTE = 'field_quote'*
704710

705-
*FIELDQUOTE* only applies to CSV. Specifies a single character that is used as the quote character (string delimiter) in the CSV file. If not specified, the quote character (") is used as the quote character as defined in the RFC 4180 standard. Extended ASCII and multi-byte characters and aren't supported with UTF-8 for FIELDQUOTE.
711+
*FIELDQUOTE* only applies to CSV. Specifies a single character that is used as the quote character (string delimiter) in the CSV file. If not specified, the quote character (") is used as the quote character as defined in the RFC 4180 standard. Hexadecimal notation is also supported for FIELDQUOTE. Extended ASCII and multi-byte characters aren't supported with UTF-8 for FIELDQUOTE.
706712

707713
> [!NOTE]
708714
> FIELDQUOTE characters are escaped in string columns where there is a presence of a double FIELDQUOTE (delimiter).
709715
710716
#### *FIELDTERMINATOR = 'field_terminator'*
711717

712-
*FIELDTERMINATOR* only applies to CSV. Specifies the field terminator that is used in the CSV file. The field terminator can also be specified using hexadecimal notation. The field terminator can be multi-character. The default field terminator is a (,). Extended ASCII and multi-byte characters and aren't supported with UTF-8 for FIELDTERMINATOR.
718+
*FIELDTERMINATOR* only applies to CSV. Specifies the field terminator that is used in the CSV file. The field terminator can also be specified using hexadecimal notation. The field terminator can be multi-character. The default field terminator is a (,). Extended ASCII and multi-byte characters aren't supported with UTF-8 for FIELDTERMINATOR.
713719

714720
#### ROWTERMINATOR = 'row_terminator'
715721

716-
*ROWTERMINATOR* only applies to CSV. Specifies the row terminator that is used in the CSV file. The row terminator can be specified using hexadecimal notation. The row terminator can be multi-character. Default terminators for PARSER_VERSION = '1.0' are `\r\n`, `\n`, and `\r`. Default terminators for PARSER_VERSION = '2.0' are `\r\n` and `\n`.
722+
*ROWTERMINATOR* only applies to CSV. Specifies the row terminator that is used in the CSV file. The row terminator can be specified using hexadecimal notation. The row terminator can be multi-character. The default terminators are `\r\n`, `\n`, and `\r`.
717723

718724
The COPY command prefixes the `\r` character when specifying `\n` (newline) resulting in `\r\n`. To specify only the `\n` character, use hexadecimal notation (`0x0A`). When specifying multi-character row terminators in hexadecimal, don't specify 0x between each character.
719725

720-
Extended ASCII and multi-byte characters and aren't supported with UTF-8 for ROWTERMINATOR.
726+
Extended ASCII and multi-byte characters aren't supported with UTF-8 for ROWTERMINATOR.
721727

722728
#### *FIRSTROW = First_row_int*
723729

@@ -735,7 +741,9 @@ Parser version 2.0 has the following limitations:
735741

736742
- Compressed CSV files are not supported
737743
- Files with UTF-16 encoding are not supported
738-
- Multicharacter ROWTERMINATOR, FIELDTERMINATOR, or FIELDQUOTE is not supported. However, '\r\n' is accepted as a default ROWTERMINATOR
744+
- Multicharacter or multibyte ROWTERMINATOR, FIELDTERMINATOR, or FIELDQUOTE is not supported. However, '\r\n' is accepted as a default ROWTERMINATOR
745+
746+
When using parser version 1.0 with UTF-8 files, multibyte and multicharacter terminators are not supported for FIELDTERMINATOR.
739747

740748
Parser version 1.0 is available for backward compatibility only, and should be used only when these limitations are encountered.
741749

@@ -767,7 +775,7 @@ The default values of the COPY command are:
767775

768776
- COMPRESSION default is uncompressed
769777

770-
- FIELDQUOTE = ''
778+
- FIELDQUOTE = '"'
771779

772780
- FIELDTERMINATOR = ','
773781

@@ -854,11 +862,11 @@ WITH (
854862

855863
### What is the file splitting guidance for the COPY command loading compressed CSV files?
856864

857-
Consider splitting large CSV files, but keep files at a minimum of 4 MB each for better performance.
865+
Consider splitting large CSV files, especially when the number of files is small, but keep files at a minimum of 4 MB each for better performance.
858866

859867
### What is the file splitting guidance for the COPY command loading Parquet files?
860868

861-
There's no need to split Parquet because the COPY command splits files automatically. Parquet files in the Azure storage account should be 256 MB or larger for best performance.
869+
Consider splitting large Parquet files, especially when the number of files is small.
862870

863871
### Are there any limitations on the number or size of files?
864872

0 commit comments

Comments
 (0)