-- Unload to external stage
COPY INTO @s3_stage/unload/
FROM my_table
FILE_FORMAT = (TYPE = PARQUET COMPRESSION = SNAPPY)
OVERWRITE = TRUE;
-- Partitioned unload
COPY INTO @s3_stage/unload/
FROM my_table
PARTITION BY ('dt=' || DATE(sale_date))
FILE_FORMAT = (TYPE = CSV)
HEADER = TRUE;
-- Validate unload
SELECT COUNT(*) FROM @s3_stage/unload/;
Unload Patterns
Pattern
When to Use
CSV with header
Data sharing, BI tools
Parquet snappy
Efficient columnar, downstream ETL
JSON
API consumption
Partitioned
Hive-style partitioning for Spark/Athena
Best Practices
Use OVERWRITE = TRUE for idempotent exports
Add SINGLE = TRUE to get one file (not parallel)
Set MAX_FILE_SIZE for file size control
COPY INTO @s3_stage/report.csv
FROM (SELECT * FROM my_table ORDER BY id)
FILE_FORMAT = (TYPE = CSV HEADER = TRUE)
SINGLE = TRUE
MAX_FILE_SIZE = 500000000;
✏️ Exercise: Unload a table to S3 in Parquet format with Snappy compression. Verify the files in S3.