> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Exporting Data

> Copy-paste examples of exporting data with SQL

## EXPORT ... INTO

### Sources (Table/Query)

<CodeGroup>
  ```sql Table theme={null}
  EXPORT TABLE employee
  INTO FILE PATH '/export/employee.csv'
  ```

  ```sql Query theme={null}
  EXPORT QUERY
  (
      SELECT id, manager_id, first_name, last_name, salary, hire_date
      FROM employee
      WHERE dept_id = 2
  )
  INTO FILE PATH '/export/employee_dept2.csv'
  ```
</CodeGroup>

### Data Sinks (File/Table/DML)

<CodeGroup>
  ```sql File theme={null}
  EXPORT TABLE employee
  INTO FILE PATH '/data/employee.csv'
  WITH OPTIONS (DATASINK_NAME = 's3_dsink')
  ```

  ```sql Table (via JDBC) theme={null}
  EXPORT TABLE employee
  INTO REMOTE TABLE 'example.remote_employee'
  WITH OPTIONS (DATASINK_NAME = 'jdbc_dsink')
  ```

  ```sql DML (via JDBC) theme={null}
  EXPORT TABLE employee
  INTO REMOTE QUERY 'INSERT INTO example.remote_employee VALUES (?, ?, ?, ?, ?, ?, ?)'
  WITH OPTIONS (DATASINK_NAME = 'jdbc_dsink')
  ```

  ```sql Init Options (via JDBC) theme={null}
  EXPORT TABLE ts_source
  INTO REMOTE TABLE 'ts'
  WITH OPTIONS
  (
  	DATASINK_NAME = 'jdbc_dsink',
  	JDBC_SESSION_INIT_STATEMENT = 'SET TIMEZONE=''EST''',
  	JDBC_CONNECTION_INIT_STATEMENT = 'CREATE TABLE ts (ts DATETIME)'
  )
  ```
</CodeGroup>

### Delimited Text Options

<CodeGroup>
  ```sql CSV theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products.csv'
  ```

  ```sql Forced Format theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products_text.dat'
  FORMAT TEXT
  ```

  ```sql No Header theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products.csv'
  FORMAT TEXT (INCLUDES HEADER = FALSE)
  ```

  ```sql Columns Mapped by Name theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products_name.csv'
  WITH OPTIONS (FIELDS MAPPED BY NAME(id, name, stock))
  ```

  ```sql Columns Ignored by Position theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products_pos.csv'
  WITH OPTIONS (FIELDS IGNORED BY POSITION(2, 4))
  ```

  ```sql Parsing Options theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products.ssv'
  FORMAT TEXT
  (
      DELIMITER = ';',
      INCLUDES HEADER = TRUE,
      NULL = '<null>'
  )
  ```

  ```sql GZip Compression theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products.csv.gz'
  WITH OPTIONS (COMPRESSION_TYPE = 'gzip')
  ```
</CodeGroup>

### Parquet Files

<CodeGroup>
  ```sql Parquet Format theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products_par.dat'
  FORMAT PARQUET
  ```

  ```sql Properties Mapped By Name theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products_name.parquet'
  FORMAT PARQUET
  WITH OPTIONS (FIELDS MAPPED BY NAME(id, name, stock))
  ```

  ```sql Properties Ignored By Name theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products_pos.parquet'
  FORMAT PARQUET
  WITH OPTIONS (FIELDS IGNORED BY POSITION(category, description))
  ```

  ```sql Snappy Compression (default) theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products.parquet'
  ```

  ```sql GZip Compression theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products.gz.parquet'
  WITH OPTIONS (COMPRESSION_TYPE = 'gzip')
  ```
</CodeGroup>

### Naming Options

<CodeGroup>
  ```sql Single File w/o Code theme={null}
  -- Creates a file with a name like:
  --   export/product.csv
  EXPORT TABLE product
  INTO FILE PATH '/export/product.csv'
  WITH OPTIONS (SINGLE_FILE = 'overwrite')
  ```

  ```sql Single File w/ Code theme={null}
  -- Creates a file with a name like:
  --   export/product_611460000.csv
  EXPORT TABLE product
  INTO FILE PATH '/export/product.csv'
  ```

  ```sql Multiple Files w/ Code theme={null}
  -- Creates a set of files with names like:
  -- * export/product_611641000.csv
  -- * export/product_611642000.csv
  EXPORT TABLE product
  INTO FILE PATH '/export/product.csv'
  WITH OPTIONS (SINGLE_FILE = false)
  ```
</CodeGroup>

### Sizing Options

<CodeGroup>
  ```sql Batch (Local File) theme={null}
  EXPORT TABLE product
  INTO FILE PATH '/export/products_exp.csv'
  WITH OPTIONS (BATCH SIZE = 20000)
  ```

  ```sql Batch (Remote Table) theme={null}
  EXPORT TABLE product
  INTO REMOTE TABLE 'product_exp'
  WITH OPTIONS
  (
  	DATASINK_NAME = 'jdbc_dsink',
  	BATCH SIZE = 20000
  )
  ```
</CodeGroup>
