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

# COPY INTO

> Unload a query's results to a CSV file in cloud object storage.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Statement</span></div>

`COPY INTO` writes the results of a query to a file in object storage. Use it to export result sets that are too large to download from the [query editor](/query/querying/query-editor), which returns at most 10,000 rows.

## Syntax

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
COPY INTO '<storage path>'
FROM (<query>)
[ MAX_FILE_SIZE <bytes> ]
[ SINGLE <boolean> ];
```

| Parameter | Description |
| - | - |
| `<storage path>` | Full path of the output file, for example `s3://sample/unloads/call_center.csv`. Must be a file path, not a folder. |
| `<query>` | The query whose results are written. |
| `MAX_FILE_SIZE` | Maximum output file size, in bytes. |
| `SINGLE` | `false` (default) or `true`. See [Limitations](#limitations). |

## Example

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
COPY INTO 's3://sample/unloads/call_center_files.csv'
FROM (SELECT * FROM call_center ORDER BY cc_call_center_sk)
MAX_FILE_SIZE 5000000000
SINGLE false;
```

## Before you start

* You need the **DataExport** role to run `COPY INTO` from the query editor. See [Roles and permissions](/platform/identity/roles-and-permissions).
* The workspace needs write access to the target bucket. See the [CloudPrem prerequisites](/platform/deploy/aws-cloudprem/prerequisites).

## Output format

Files are written as CSV with these settings:

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
TYPE = CSV
RECORD_DELIMITER = '\n'
FIELD_DELIMITER = ","
FILE_EXTENSION = null
SKIP_HEADER = 0
DATE_FORMAT = "YYYY-MM-DD"
TIME_FORMAT = "HH24:MI:SS"
TIMESTAMP_FORMAT = "YYYY-MM-DD HH24:MI:SS"
ESCAPE = NONE
ESCAPE_UNENCLOSED_FIELD = "\\"
TRIM_SPACE = false
FIELD_OPTIONALLY_ENCLOSED_BY = '\"'
NULL_IF = ('\"\"')
COMPRESSION = Auto
EMPTY_FIELD_AS_NULL = true
ENCODING = UTF8
SINGLE = false
```

## Limitations

* AWS S3 is the only supported destination.
* CSV is the only output format, and files aren't compressed.
* The path must point to a file. Folder paths such as `s3://sample/unloads/` aren't supported.
* Exports are written to a single file.
* `NULL` values are written as `""` in every column, whatever the column type.
* Dates are written as `YYYY-MM-DD` and timestamps as `YYYY-MM-DD HH24:MI:SS`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.