Snowflake

Snowflake COPY INTO Practical Design Guide: Load, Unload, and FILE FORMAT

2026-03-26
更新: 2026-03-27
NicheeLab Editorial Team

COPY INTO is Snowflake's core command for data loading and unloading. A single command handles bulk loads from a stage into a table and exports from a table back out to a stage, and its rich options — FILE FORMAT, ON_ERROR, and VALIDATION_MODE — give you the flexibility to build production-grade data pipelines.

On the SnowPro Core exam, COPY INTO falls under Domain 4 (Data Loading & Unloading, 10-15% of the exam). The Data Engineer exam goes even deeper into its options. This article organizes COPY INTO end-to-end from a practical design perspective and highlights the points that come up most often on the exams.

COPY INTO (Load) Syntax

The basic syntax for loading data from a stage into a table:

COPY INTO <table_name>
  FROM @<stage_name>/<path>/
  FILE_FORMAT = (FORMAT_NAME = '<file_format_name>'
                 | TYPE = CSV | JSON | PARQUET | AVRO | ORC | XML)
  PATTERN = '.*\.csv\.gz'
  ON_ERROR = ABORT_STATEMENT | CONTINUE | SKIP_FILE | SKIP_FILE_<N>
  PURGE = TRUE | FALSE
  FORCE = TRUE | FALSE;

Key Parameters

ParameterDefaultDescription
FILE_FORMATCSVSpecifies the file format. Use a named FILE FORMAT or an inline definition.
PATTERN(none)Regex to filter which files get loaded
ON_ERRORABORT_STATEMENTBehavior when an error occurs. CONTINUE and SKIP_FILE are also available.
PURGEFALSEWhen TRUE, files in the stage are auto-deleted after a successful load.
FORCEFALSEWhen TRUE, files already loaded within the last 64 days will be re-loaded.
VALIDATION_MODE(none)Dry run. RETURN_ERRORS / RETURN_ALL_ERRORS / RETURN_N_ROWS.

How COPY INTO Prevents Duplicate Loads

By default, COPY INTO keeps 64 days of load-history metadata and automatically prevents the same file from being loaded twice. When a file's path, size, and last-modified timestamp match the metadata, the file is skipped. You can override this with FORCE = TRUE, but the best practice is to leave duplicate prevention enabled in production.

COPY INTO (Unload) Syntax

The syntax for exporting data from a table out to a stage:

COPY INTO @<stage_name>/<path>/
  FROM <table_name> | (<SELECT statement>)
  FILE_FORMAT = (TYPE = CSV | JSON | PARQUET)
  SINGLE = TRUE | FALSE
  MAX_FILE_SIZE = <bytes>
  HEADER = TRUE | FALSE
  OVERWRITE = TRUE | FALSE;

Key Parameters

ParameterDefaultDescription
SINGLEFALSETRUE writes to a single consolidated file; FALSE writes parallel split files.
MAX_FILE_SIZE16MBMaximum size per file when writing split output
HEADERFALSEWhen TRUE, includes a CSV header row in the output.
OVERWRITEFALSEWhen TRUE, overwrites existing files in the stage.

The FROM clause on unload accepts a SELECT statement directly, so you can export filtered, aggregated, or transformed results rather than the entire table.

Designing FILE FORMAT

FILE FORMAT is an object that defines a data format and its parsing rules. By creating a named FILE FORMAT up front, you avoid restating the options in every COPY INTO statement.

CREATE FILE FORMAT my_csv_format
  TYPE = CSV
  FIELD_DELIMITER = ','
  RECORD_DELIMITER = '\n'
  SKIP_HEADER = 1
  FIELD_OPTIONALLY_ENCLOSED_BY = '"'
  NULL_IF = ('NULL', 'null', '')
  EMPTY_FIELD_AS_NULL = TRUE
  COMPRESSION = GZIP;

Supported Formats and Use Cases

FormatPrimary Use CaseLoadUnloadNotes
CSVGeneral-purpose text dataYesYesSKIP_HEADER and FIELD_DELIMITER matter most
JSONSemi-structured dataYesYesSTRIP_OUTER_ARRAY and STRIP_NULL_VALUES come up often
ParquetColumnar analytics dataYesYesDefaults to SNAPPY compression
AvroBinary with schemaYesYesSupports schema evolution
ORCHadoop interoperabilityYesNoLoad only
XMLLegacy system integrationYesNoLoad only

Choosing the Right ON_ERROR Option

ON_ERROR is the key parameter that defines your error-handling strategy on data load.

ON_ERROR valueBehaviorRecommended Use
ABORT_STATEMENT (default)A single error row rolls back the entire loadProduction loads of pre-validated data
CONTINUESkip error rows and load only valid rowsExternal data with inconsistent quality
SKIP_FILESkip any file that contains errorsBulk loads across many files
SKIP_FILE_<N>Skip only files with N or more error rowsFilter by a fixed quality threshold
SKIP_FILE_<N>%Skip only files where the error rate is N% or higherPercentage-based quality filtering

When you use ON_ERROR = CONTINUE, the details of skipped error rows can be inspected after the fact with the VALIDATE function. SELECT * FROM TABLE(VALIDATE(my_table, JOB_ID => '_last')) returns the error rows from the most recent COPY INTO.

VALIDATION_MODE (Dry Run)

When VALIDATION_MODE is set, no data is loaded — Snowflake returns only the file validation results. It's a must-have for pre-flight checks before a production load.

ModeBehaviorUse Case
RETURN_<N>_ROWSValidates the first N rows and returns the resultsSanity-check file format behavior
RETURN_ERRORSReturns only error rows (subject to a max-file limit)Quality check before a production load
RETURN_ALL_ERRORSReturns every error row across every fileGenerate a comprehensive quality report
COPY INTO my_table
  FROM @my_stage/data/
  FILE_FORMAT = (FORMAT_NAME = 'my_csv_format')
  VALIDATION_MODE = 'RETURN_ERRORS';

Stage Types and How to Choose

Stage TypeManaged BySharingUse Case
User stage (@~)SnowflakeOwner onlyPersonal scratch space for files
Table stage (@%table)SnowflakePer tableDedicated to loading a specific table
Named internal stageSnowflakeControlled by roleTeam-shared file management
External stage (S3/Azure/GCS)Cloud providerControlled by IAMIntegration with existing cloud storage

Practical Design Best Practices

1. Always create a named FILE FORMAT

Inlining format options in every COPY INTO statement quickly becomes unmaintainable. Use CREATE FILE FORMAT to create a named object and reference it from COPY INTO with FORMAT_NAME. When the format needs to change, editing the FILE FORMAT object in one place propagates the change to every COPY INTO statement.

2. Pre-validate with VALIDATION_MODE

Especially for data whose quality you don't control — like CSVs received from external partners — run VALIDATION_MODE = 'RETURN_ERRORS' as a pre-check. It surfaces file format mismatches, data type errors, and NULL constraint violations before the production load runs.

3. Keep stages clean with PURGE = TRUE

Leaving loaded files behind in a stage accumulates storage cost and slows down file listing on subsequent COPY INTO runs. Either set PURGE = TRUE to auto-delete loaded files or run REMOVE @stage on a regular schedule.

4. Tune file sizes to 100-250 MB

Snowflake's documentation recommends 100-250 MB compressed as the sweet spot for COPY INTO file sizes. Files that are too small (a few KB to a few MB) carry too much overhead; files that are too large (over 1 GB) hurt parallel processing efficiency.

Check Your Understanding

SnowPro Core - Data Loading

問題 1

Which statement correctly describes the behavior of COPY INTO when ON_ERROR = 'CONTINUE' is set?

  1. If even one row contains an error, the entire COPY INTO is rolled back
  2. Rows with errors are skipped, and only valid rows are loaded into the table
  3. The entire file containing an error is skipped, and only the remaining files are loaded
  4. Errors are recorded to a log table, then all rows (including error rows) are loaded

正解: B

With ON_ERROR = 'CONTINUE', any row that errors out (row-level data type errors, NULL constraint violations, etc.) is skipped, and only the valid rows are loaded into the table (B is correct). Option A describes ON_ERROR = 'ABORT_STATEMENT' (the default). Option C describes ON_ERROR = 'SKIP_FILE', which skips at the file level. The behavior in option D — loading every row including error rows — does not exist for any ON_ERROR option. Details of rows skipped under CONTINUE can be reviewed after the fact via the VALIDATE function: SELECT * FROM TABLE(VALIDATE(table, JOB_ID => '_last')).

Frequently Asked Questions

When should I use COPY INTO vs Snowpipe?

Use COPY INTO for batch loads of file sets, and Snowpipe to auto-load files as soon as they land in a stage. COPY INTO uses Virtual Warehouse compute and gives you explicit control over execution timing. Snowpipe runs on serverless compute and is triggered automatically by cloud storage event notifications (S3: SQS / Azure: Event Grid / GCP: Pub/Sub). COPY INTO fits daily batch loads; Snowpipe fits near-real-time continuous ingestion. On cost, COPY INTO is better for large files loaded infrequently, while Snowpipe is better for small files loaded frequently.

Which ON_ERROR option should I choose?

The right ON_ERROR option depends on data quality requirements and business impact. For initial production loads or pre-validated data, use ABORT_STATEMENT (the default): a single error row rolls back the entire load, guaranteeing data integrity. For data with inconsistent quality (such as CSVs from external partners), use CONTINUE to skip error rows and post-process them after the load. SKIP_FILE works well for bulk loading many files at once — files containing errors are skipped while clean files load. SKIP_FILE_<N> and SKIP_FILE_<N>% let you set an error tolerance threshold.

What is VALIDATION_MODE?

VALIDATION_MODE is COPY INTO's dry-run feature: it validates files without actually loading any data. It has three modes — RETURN_<N>_ROWS (returns the first N rows), RETURN_ERRORS (returns only error rows), and RETURN_ALL_ERRORS (returns every error row across all files). The best practice is to run VALIDATION_MODE = 'RETURN_ERRORS' before a production load to catch file format mismatches and data type errors up front. When VALIDATION_MODE is set, no data is loaded at all, so you can test safely.

Practice more COPY INTO questions

Sharpen your COPY INTO knowledge with questions from the Data Loading & Unloading domain.

Try free questions

Related Snowflake Data Loading Articles

Snowpipe: Complete Guide

How automatic data loading works and how to set it up

Designing Snowflake Stages

When to use internal vs. external stages and how to design them

Working with Semi-Structured Data

Using the VARIANT type, FLATTEN, and colon notation

80 Essential Snowflake Terms

Key exam terms organized by category

Check what you learned with practice questions

Practice with certification-focused question sets

無料で問題を解いてみる
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Snowflake

Snowflake Certifications: All 11 Exams Explained (2026)

Every SnowPro certification — Associate, Core, Specialty, Ad...

Snowflake

Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)

All 11 SnowPro exams ranked by difficulty with study-time es...

Snowflake

Snowflake Study Guide: Fastest Pass Route by Exam (2026)

How to pass SnowPro certifications efficiently — official ma...

Snowflake

SnowPro Core (COF-C03): Complete Exam Guide (2026)

Pass the SnowPro Core exam — six domains, scope, sample ques...

Snowflake

SnowPro Associate Platform (SOL-C01): Complete Guide (2026)

The entry-level SnowPro Associate exam — scope, weighting, s...

Browse all Snowflake articles (103)
© 2026 NicheeLab All rights reserved.