Choose files and diagnose bad rows
Select the intended files, validate their records, then choose what a real load should do when a row fails.
Understand the idea
Save the supplied bad.csv and upload it to bad/ using the same method as lesson 1. FILES is easiest for a controlled replay; use a narrow PATTERN for a batch. Avoid combining both selectors.
| Concept | What it means |
|---|---|
| FILES | Explicit list of file names relative to the stage path. |
| PATTERN | Regular expression selecting file paths. |
| VALIDATION_MODE | Checks without inserting rows. |
| ON_ERROR | ABORT_STATEMENT, CONTINUE or skip a problem file. |
| VALIDATE | Inspect errors from a supported earlier COPY job. |
A concrete example
A file contains amount=banana. Validation reports a conversion error; CONTINUE loads the valid row.
Remember: A successful statement can still reject rows. Read rows parsed, rows loaded and error counts.
Explain it step by step · full theory
How to apply it
Save the supplied bad.csv and upload it to bad/ using the same method as lesson 1. FILES is easiest for a controlled replay; use a narrow PATTERN for a batch. Avoid combining both selectors.
VALIDATION_MODE does not support transformation loads or MATCH_BY_COLUMN_NAME. VALIDATE does not support transformed COPY jobs and returns no records for ABORT_STATEMENT loads; use the original query error for those. Run the COPY and query-ID capture consecutively in the same session.
Words used in this lesson
- FILES
- Explicit list of file names relative to the stage path.
- PATTERN
- Regular expression selecting file paths.
- VALIDATION_MODE
- Checks without inserting rows.
- ON_ERROR
- ABORT_STATEMENT, CONTINUE or skip a problem file.
- VALIDATE
- Inspect errors from a supported earlier COPY job.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Choose files and diagnose bad rows
Understand the input
Select the intended files, validate their records, then choose what a real load should do when a row fails.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Understand the input
Select the intended files, validate their records, then choose what a real load should do when a row fails.
- Follow the example
A file contains amount=banana. Validation reports a conversion error; CONTINUE loads the valid row.
- Check the outcome
A successful statement can still reject rows. Read rows parsed, rows loaded and error counts.
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Manual examples only. Start with this module’s first lesson to create L2_OBJECTS_LAB.M6_LAB. In each new SQL session select that schema and an authorized warehouse. Later lessons state additional prerequisites. Upload file contents through Snowsight or a supported client; never run CSV as SQL.
Save as bad.csv and upload to bad/
order_id,amount
3,15.00
4,bananaWhat to expect and why
Two data rows: one valid amount and one deliberate conversion failure.
Validate without loading
CREATE TABLE M6_ERRORS LIKE M6_ORDERS;
COPY INTO M6_ERRORS FROM @M6_FILES/bad/
FILES=('bad.csv') FILE_FORMAT=(FORMAT_NAME='M6_CSV')
VALIDATION_MODE=RETURN_ERRORS;What to expect and why
Reports the invalid amount; the new table remains empty.
Allow valid rows, inspect rejected rows
COPY INTO M6_ERRORS FROM @M6_FILES/bad/
PATTERN='.*bad[.]csv$' FILE_FORMAT=(FORMAT_NAME='M6_CSV')
ON_ERROR=CONTINUE;
SET m6_copy_id = LAST_QUERY_ID();
SELECT * FROM TABLE(VALIDATE(M6_ERRORS, JOB_ID => $m6_copy_id));
SELECT * FROM M6_ERRORS;What to expect and why
On the first load, order 3 is inserted and order 4 is rejected. Capture the COPY query ID before another query changes LAST_QUERY_ID().
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
When would SKIP_FILE be preferable to CONTINUE?
Compare your reasoning
When partial files are unacceptable but other files in the batch may load. ABORT_STATEMENT instead stops the statement on an error.