doc/user/content/sql/copy-to.md
COPY TO outputs results from Materialize to standard output or object storage.
This command is useful to output SUBSCRIBE results
to stdout, or perform bulk exports to Amazon S3.
{{< tabs >}} {{< tab "Copy to stdout" >}}
stdout {#copy-to-stdout}Copying results to stdout is useful to output the stream of updates from a
SUBSCRIBE command in interactive SQL clients like psql.
{{% include-syntax file="examples/copy_to" example="syntax-stdout" %}}
{{< /tab >}} {{< tab "Copy to Amazon S3 and S3 compatible services" >}}
Copying results to Amazon S3 (or S3-compatible services) is useful to perform tasks like periodic backups for auditing, or downstream processing in analytical data warehouses like Snowflake, Databricks or BigQuery. For step-by-step instructions, see the integration guide for Amazon S3.
The COPY TO command is one-shot: every time you want to export results, you
must run the command. To automate exporting results on a regular basis, you can
set up scheduling, for example using a simple cron-like service or an
orchestration platform like Airflow or Dagster.
{{% include-syntax file="examples/copy_to" example="syntax-s3" %}}
{{< /tab >}} {{< /tabs >}}
{{% include-from-yaml data="examples/copy_to" name="csv-writer-settings" %}}
{{% include-from-yaml data="examples/copy_to" name="parquet-writer-settings" %}}
{{% include-from-yaml data="examples/copy_to" name="parquet-data-types" %}}
The privileges required to execute this statement are:
{{% include-headless "/headless/sql-command-privileges/copy-to" %}}
COPY (SUBSCRIBE some_view) TO STDOUT WITH (FORMAT binary);
COPY some_view TO 's3://mz-to-snow/parquet/'
WITH (
AWS CONNECTION = aws_role_assumption,
FORMAT = 'parquet'
);
{{< include-from-yaml data="examples/copy_to" name="parquet-writer-settings" >}}
See also Copy to S3: Parquet Data Types.
COPY some_view TO 's3://mz-to-snow/csv/'
WITH (
AWS CONNECTION = aws_role_assumption,
FORMAT = 'csv'
);
{{% include-from-yaml data="examples/copy_to" name="csv-writer-settings" %}}
CREATE CONNECTION