Skip to content

Commit 9948d0c

Browse files
Merge pull request #28831 from periclesrocha/patch-8
Adding documentation for PARSER_VERSION=2.0
2 parents 5e13be8 + 714aace commit 9948d0c

1 file changed

Lines changed: 47 additions & 23 deletions

File tree

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

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Use the COPY statement in Azure Synapse Analytics and Warehouse in
55
author: periclesrocha
66
ms.author: procha
77
ms.reviewer: wiassaf, mikeray
8-
ms.date: 06/05/2023
8+
ms.date: 10/27/2023
99
ms.service: sql
1010
ms.subservice: t-sql
1111
ms.topic: language-reference
@@ -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

@@ -572,6 +575,7 @@ WITH
572575
[ , ROWTERMINATOR = 'row_terminator' ]
573576
[ , FIRSTROW = first_row ]
574577
[ , ENCODING = { 'UTF8' | 'UTF16' } ]
578+
[ , PARSER_VERSION = { '1.0' | '2.0' } ]
575579
)
576580
```
577581

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

584588
#### *schema_name*
585589

586-
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.
587591

588592
#### *table_name*
589593

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

600604
- *Column_name* - the name of the column in the target table.
601605
- *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'
602-
- *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.
603607
- The field indexing starts at 1.
604608

605609
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.
@@ -668,9 +672,12 @@ Multiple file locations can only be specified from the same storage account and
668672

669673
*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.
670674

675+
> [!NOTE]
676+
> When a relative path is passed to *ERRORFILE*, the path is relative to the container path specified in *external_location*.
677+
671678
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.
672679

673-
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.
674681

675682
#### *ERRORFILE_CREDENTIAL = (IDENTITY= '', SECRET = '')*
676683

@@ -686,7 +693,7 @@ If ERRORFILE has the full path of the storage account defined, then the ERRORFIL
686693
687694
#### *MAXERRORS = max_errors*
688695

689-
*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.
690697

691698
#### *COMPRESSION = { 'Snappy' | 'GZIP' | 'NONE'}*
692699

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

702709
#### *FIELDQUOTE = 'field_quote'*
703710

704-
*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.
705712

706713
> [!NOTE]
707714
> FIELDQUOTE characters are escaped in string columns where there is a presence of a double FIELDQUOTE (delimiter).
708715
709716
#### *FIELDTERMINATOR = 'field_terminator'*
710717

711-
*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.
712719

713-
#### ROW TERMINATOR = 'row_terminator'
720+
#### ROWTERMINATOR = 'row_terminator'
714721

715-
*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`.
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`.
716723

717724
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.
718725

719-
Extended ASCII and multi-byte characters and aren't supported with UTF-8 for ROW TERMINATOR.
726+
Extended ASCII and multi-byte characters aren't supported with UTF-8 for ROWTERMINATOR.
720727

721728
#### *FIRSTROW = First_row_int*
722729

@@ -726,6 +733,23 @@ Extended ASCII and multi-byte characters and aren't supported with UTF-8 for ROW
726733

727734
ENCODING only applies to CSV. Default is UTF8. Specifies the data encoding standard for the files loaded by the COPY command.
728735

736+
#### PARSER_VERSION = { '1.0' | '2.0' }
737+
738+
PARSER_VERSION only applies to CSV. Default is 2.0. Specifies the file parser used for ingestion when the source file type is CSV. The 2.0 parser offers improved performance for ingestion of CSV files.
739+
740+
Parser version 2.0 has the following limitations:
741+
742+
- Compressed CSV files are not supported
743+
- Files with UTF-16 encoding are not supported
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.
747+
748+
Parser version 1.0 is available for backward compatibility only, and should be used only when these limitations are encountered.
749+
750+
> [!NOTE]
751+
> When COPY INTO is used with compressed CSV files or files with UTF-16 encoding, COPY INTO automatically switches to PARSER_VERSION 1.0, without user action required. For multi-character terminators on FIELDTERMINATOR or ROWTERMINATOR, the COPY INTO statement will fail. Use PARSER_VERSION = '1.0' if multi-character separators are needed.
752+
729753
## Remarks
730754

731755
COPY INTO in [!INCLUDE [fabricdw](../../includes/fabric-dw.md)] doesn't allow setting a date format for interpreting date character strings. By default, all dates are considered to have the month-day-year format. To ingest a CSV file with a different date format, use *SET DATEFORMAT* to specify the desired date format at the session level. For more information, see [SET DATEFORMAT (Transact-SQL)](set-dateformat-transact-sql.md).
@@ -751,7 +775,7 @@ The default values of the COPY command are:
751775

752776
- COMPRESSION default is uncompressed
753777

754-
- FIELDQUOTE = ''
778+
- FIELDQUOTE = '"'
755779

756780
- FIELDTERMINATOR = ','
757781

@@ -838,11 +862,11 @@ WITH (
838862

839863
### What is the file splitting guidance for the COPY command loading compressed CSV files?
840864

841-
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.
842866

843867
### What is the file splitting guidance for the COPY command loading Parquet files?
844868

845-
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.
846870

847871
### Are there any limitations on the number or size of files?
848872

0 commit comments

Comments
 (0)