Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
Snowflake · SnowPro Core

COPY INTO, Error Handling, and Unloading

SnowPro Core · Lesson 16 of 27 · 1:56:22

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the SnowPro Core Certification exam (COF-C03). In this lesson: loading with COPY INTO and transformations, ON_ERROR and validation, load metadata, and unloading data. Follows Foxglove Apparel, a fictional online clothing retailer. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

The nightly load

Foxglove's order files now sit on a stage, and the nightly job must load them into the orders table. Some files have a bad date in a few rows, some were already loaded yesterday, and finance also wants a monthly extract sent back out to cloud storage. COPY INTO handles all of this, in both directions.

Loading with COPY INTO

COPY INTO a table loads staged files, using a running warehouse, and you can pick the files with a list of file names, or with a pattern. The number of load operations that run in parallel cannot exceed the number of files, which is another reason to split large files. A simple transformation can happen during the load, with a SELECT that reorders, omits, or casts columns. But COPY transformations do not support FLATTEN, joins, GROUP BY, or a WHERE filter.

Matching columns

For files with named fields, such as Parquet or JSON, MATCH_BY_COLUMN_NAME loads each field into the column with the same name. INFER_SCHEMA detects the column definitions of staged files, and CREATE TABLE with USING TEMPLATE builds a table from them. Schema evolution can also let a table add new columns automatically, when new fields appear in loaded files. And TRUNCATECOLUMNS cuts text strings that are longer than the target column, instead of failing.

Error handling

When files contain bad rows, the ON_ERROR option decides what happens. ABORT_STATEMENT, the default for bulk loads, stops the whole load at the first error. CONTINUE skips the bad rows and loads the rest, SKIP_FILE skips any file that contains an error, and SKIP_FILE with a number or a percentage skips a file only when its errors reach that threshold. For Snowpipe, the default is SKIP_FILE instead.

Validation

VALIDATION_MODE checks files without loading them. RETURN_ERRORS returns every error in the files, while RETURN followed by a number of rows validates that many rows, and fails at the first error. After a load, the VALIDATE table function returns the errors of a previous COPY job. And to capture the rejected rows themselves, you can turn on error logging for the table, and load with ON_ERROR set to CONTINUE.

Load metadata

Snowflake keeps load metadata for each table, recording which files were loaded, for sixty-four days. So running the same COPY twice does not load a file twice: files already loaded are skipped. FORCE set to TRUE reloads every file, ignoring the metadata, which can duplicate data. And when the load status of a file is unknown, because it is older than sixty-four days, LOAD_UNCERTAIN_FILES set to TRUE loads it, while still using any metadata available.

Unloading data

COPY INTO a location unloads a table, or a query result, to a stage, as CSV, JSON, or Parquet files. By default, it writes several files in parallel, each of about sixteen megabytes at most, and MAX_FILE_SIZE can raise that up to five gigabytes. SINGLE set to TRUE writes a single file, HEADER adds column names to CSV files, and PARTITION BY splits the output into paths, such as one per day. Then GET downloads unloaded files from an internal stage to a client.

Recap

Let's recap. COPY INTO a table loads staged files with a warehouse, and allows simple transformations, but no joins, FLATTEN, or WHERE. MATCH_BY_COLUMN_NAME and INFER_SCHEMA help with files whose fields have names. ON_ERROR defaults to ABORT_STATEMENT for bulk loads, and to SKIP_FILE for Snowpipe, and validation mode checks files without loading them. Load metadata prevents reloading files for sixty-four days, unless you use FORCE. And COPY INTO a location unloads data, in files of sixteen megabytes by default, with SINGLE, HEADER, and PARTITION BY.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. A partner sends Foxglove Parquet files whose fields match the column names of the target table, but in a different order. Which option loads each field into the right column?

    • MATCH_BY_COLUMN_NAME
    • TRUNCATECOLUMNS = TRUE
    • A SELECT with FLATTEN in the COPY
    • ENABLE_SCHEMA_EVOLUTION
    Show the answer

    MATCH_BY_COLUMN_NAME

    MATCH_BY_COLUMN_NAME loads each field into the column that has the same name, whatever the order. “TRUNCATECOLUMNS = TRUE” only shortens strings that are too long. “A SELECT with FLATTEN in the COPY” is wrong, because COPY transformations do not support FLATTEN. And “ENABLE_SCHEMA_EVOLUTION” adds columns for new fields, but it does not match the existing ones.

  2. Before the first nightly run, Foxglove wants to see every parsing error in a new batch of order files, without loading a single row. What should it run?

    • COPY INTO with ON_ERROR = CONTINUE
    • COPY INTO with ON_ERROR = SKIP_FILE
    • COPY INTO with VALIDATION_MODE = RETURN_ERRORS
    • COPY INTO with FORCE = TRUE
    Show the answer

    COPY INTO with VALIDATION_MODE = RETURN_ERRORS

    Validation mode checks the files and returns every error, without loading any data. “COPY INTO with ON_ERROR = CONTINUE” would load all the valid rows. “COPY INTO with ON_ERROR = SKIP_FILE” would still load every file that has no error. And “COPY INTO with FORCE = TRUE” would load the files, even the ones loaded before.

  3. Finance wants Foxglove’s monthly sales unloaded to its S3 stage, split into one folder per region, so that another tool can read each region separately. Which option fits?

    • SINGLE = TRUE
    • MAX_FILE_SIZE = 5368709120
    • HEADER = TRUE
    • PARTITION BY region
    Show the answer

    PARTITION BY region

    PARTITION BY writes the rows of each region into a separate path, like a folder. “SINGLE = TRUE” would write everything into a single file. “MAX_FILE_SIZE = 5368709120” only changes the maximum size of each file. And “HEADER = TRUE” only adds column names to the files.