Skip to main content

COPY INTO <location>

This command unloads data from a table (or query) into one or more files in one of the following locations:

  • User / Internal / External stages: See Understanding Stages to learn about stages in Databend.
  • Buckets or containers created in a storage service.

See Also: COPY INTO table

Syntax

COPY INTO { internalStage | externalStage | externalLocation }
FROM { [<database_name>.]<table_name> | ( <query> ) }
[ FILE_FORMAT = ( { TYPE = { CSV | JSON | NDJSON | PARQUET } [ formatTypeOptions ] } ) ]
[ copyOptions ]
[ VALIDATION_MODE = RETURN_ROWS ]

internalStage

internalStage ::= @<internal_stage_name>[/<path>]

externalStage

externalStage ::= @<external_stage_name>[/<path>]

externalLocation

externalLocation ::=
's3://<bucket>[<path>]'
CONNECTION = (
<connection_parameters>
)

For the connection parameters available for accessing Amazon S3-like storage services, see Connection Parameters.

FILE_FORMAT

See Input & Output File Formats.

copyOptions

copyOptions ::=
[ SINGLE = TRUE | FALSE ]
[ MAX_FILE_SIZE = <num> ]
ParameterDescriptionRequired
SINGLEWhen TRUE, the command unloads data into one single file. Default: FALSE.Optional
MAX_FILE_SIZEThe maximum size (in bytes) of each file to be created.
Effective when SINGLE is FALSE. Default: 67108864 (64 MB).
Optional

Examples

The following examples unload data into an internal stage:

-- Create a table
CREATE TABLE test_table (
id INTEGER,
name VARCHAR,
age INT
);

-- Insert data into the table
INSERT INTO test_table (id,name,age) VALUES(1,'2',3), (4, '5', 6);

-- Create an internal stage
CREATE STAGE s2;

-- Unload the data in the table into a CSV file on the stage
COPY INTO @s2 FROM test_table FILE_FORMAT = (TYPE = CSV);

-- Unload the data from a query into a parquet file on the stage
COPY INTO @s2 FROM (SELECT name, age, id FROM test_table LIMIT 100) FILE_FORMAT = (TYPE = PARQUET);
Explore Databend Cloud for FREE
Low-cost
Fast Analytics
Easy Data Ingestion
Elastic Scaling
Try it today