Skip to main content
The data extract tool is a part of the JDBC driver to unload data. You can execute the tool directly from the JDBC CLI. The tool extracts a result set to delimited or files in the target location. To invoke the JDBC CLI, see the JDBC Manual.
To use the data extract tool, you must have JDBC version 2.63 or higher.

Supported Data Extract Formats

The data extract tool supports unloading result sets into files in specific formats. Supported extract formats are:
  • CSV — Outputs result sets as text files with fields separated by a chosen delimiter.
  • Parquet — Outputs result sets as Parquet files.

General Command Structure

Here is the general structure of an extract command.
SQL
The command is case-insensitive. Each extract command must start with EXTRACT TO. The location type location_type must be either LOCAL for the local machine or S3 for S3. You can enclose additional options within a pair of parentheses following the keyword OPTIONS. The location type is required and there are required options for each location type. For the LOCAL location type, the options must define the file prefix file_prefix, and for S3, the options must define the file prefix file_prefix, bucket bucket, and endpoint endpoint. Next, the query follows the keyword AS. This example is a simple general command structure.
SQL
For supported options, see Data Extract Options.

Specify Options, Quoting, and Escaping Quotes

Here is the general format of options.
SQL
You need to follow certain guidelines when you specify options. Keys (option names) can only consist of alphanumeric characters and are unquoted. Values can be either quoted (with the reserved character ") or unquoted. If values are unquoted, they can only contain alphanumeric characters. If the value has a non-alphanumeric character, you must quote it with the reserved character ". Note that the single quote character does not work.
SQL
To use the reserved quote character " as an argument, you must escape it with the backslash character \. To use \ as an argument, you must escape it with another \. This code illustrates both of these scenarios.
SQL

Data Extract Options

Use these optional options with the EXTRACT TO syntax and the OPTIONS keyword to configure the behavior of the extract.

General Extract Options

This table describes optional options that apply to both the LOCAL and S3 location types.
If you do not set either the MAX_ROWS_PER_FILE or the TARGET_FILE_SIZE_MB options, the data extract tool generates one output file for each partition. For a query without partitions, the tool generates a single output file.

S3 Extract Options

This table describes the required options that apply only to the S3 location type. The data extract tool ignores these options when you use the LOCAL location type. This table describes optional options that apply only to the S3 location type.

File Naming Conventions

When you use the data extract tool, the tool produces a number of files. The System determines the path of these files using multiple factors:
  • File prefix as specified by the FILE_PREFIX option
    • If the PARTITION_MODE option is not set to NONE, the file prefix must be a directory and end with a forward slash. The system creates subdirectories in the style for each partition (for example, for the KEY partition: /tmp/extract/col1=val1/col2=val2 or for the RANGE partition: /tmp/extract/val1<=col1<val2/). If the PARTITION_MODE option is set to NONE, the file prefix can be a directory or a proper prefix (for example, /tmp/extract/results_).
  • Partition mode as specified by the PARTITION_MODE option
  • Maximum number of rows, or target size in MB, for each file as specified by the MAX_ROWS_PER_FILE option
    • If you do not set a maximum number of rows per file and no target file size, this part of the convention is 0. However, if the MAX_ROWS_PER_FILE or TARGET_FILE_SIZE_MB options are set, then the system outputs rows to a single file until that limit or the lower of the two limits is reached. Then, the system generates another file with an incremented file number. The file number starts from 0.
  • Format or file extension
    • This convention applies only if the FILE_TYPE option is set to DELIMITED. For the PARQUET type, the file extension is always .parquet, even when you specify any type of compression using the PARQUET_COMPRESSION option.
  • Compression extension
    • If you specify the COMPRESSION option for an extract with the DELIMITED type, then the tool adds the compression suffix.

Examples

These examples show you how to use the data extract tool for extracting data to the local machine, extracting CSV data, and extracting Parquet data. Most of these examples assume the database already contains tables with data. For loading data, see Load Data. Local Extract to the Default Path This example extracts the results of the SELECT c1 FROM sys.dummy10 SQL query to the local machine at the relative path result-0.csv. The SQL query returns 10 rows with incremental numbers starting at 1. The OPTIONS(...) syntax is only required when you specify additional options.
SQL
sys.dummy creates a virtual table with the specified number for rows. For details, see Generate Tables Using sys.dummy.
Local CSV Extract to the Specified Path This example extracts the results of the SELECT c1 FROM sys.dummy10 SQL query to the local machine at the absolute path /home/user/out/data_0.csv. The SQL query returns 10 rows with incremental numbers starting at 1.
SQL
Local Parquet Extract with Partition by Key This example partitions customer data into a Parquet file by the country column. This partitioning creates a Hive-style directory structure on the local machine. Use the file path /home/user/customer_data/ with the KEY value for the partition strategy. Specify the target file size to be 256 MB. The SQL query selects the identifier, name, email, and country from the customers table.
SQL
The resulting file structure has these file paths.
S3 Parquet Extract with Compression This example extracts all sales data from the today_sales table to a single Parquet file on S3 using ZSTD compression. Use the S3 bucket named my-analytics-bucket with the file path daily_reports/report.parquet using the endpoint s3.us-east-1.amazonaws.com.
SQL
S3 Parquet Extract with Partitioning by Range This example extracts large event data to S3 by splitting the event_id column into 30 parallel queries using the RANGE partition strategy. Specify the maximum file size in 1024 megabytes. Override the default row group size using the PARQUET_ROW_GROUP_SIZE_BYTES option to specify 268435456 bytes (256 MB). Use the S3 bucket iot-data with the file path events/2025-09-25/ at endpoint s3.us-east-1.amazonaws.com. The SQL query selects the event identifier, sensor identifier, sensor reading, and timestamp from the events table.
SQL
Connect Using JDBC JDBC Manual
Last modified on July 2, 2026