The ShopKart files
Every night the ShopKart app exports one CSV file of the day's orders. We have two months of them (1 October to 30 November 2026), plus a customers file and a products file. One file has a bad row in it, on purpose, like real life.
shopkart/data/
โโโ customers/customers.csv 200 customers
โโโ products.csv 12 products
โโโ orders/
โโโ orders_2026-10-01.csv one file per day
โโโ orders_2026-10-02.csv
โโโ ...
โโโ orders_2026-11-30.csv โ has one broken roworder_id,customer_id,product_id,quantity,unit_price,status,order_ts
100001,148,2,1,299,PLACED,2026-10-01 19:31:04
100002,31,1,1,2499,DELIVERED,2026-10-01 16:05:15๐ปFiles
On a laptop, or in S3 / Azure / GCS
๐ฆStage
Internal (Snowflake storage) or external (your bucket)
๐ฅCOPY INTO
Reads with a file format, uses a warehouse
๐๏ธTable
shopkart.raw.orders
Step 1: a file format and a stage
USE SCHEMA shopkart.raw;
-- 1. A file format: how to read our CSV files
CREATE OR REPLACE FILE FORMAT csv_with_header
TYPE = CSV
SKIP_HEADER = 1 -- first line holds the column names
FIELD_OPTIONALLY_ENCLOSED_BY = '"'
NULL_IF = ('', 'NULL')
EMPTY_FIELD_AS_NULL = TRUE;
-- 2. An internal stage: a folder inside Snowflake to drop files into
CREATE OR REPLACE STAGE landing
FILE_FORMAT = csv_with_header
COMMENT = 'Files from the ShopKart app land here';| Stage type | Where files live | Name looks like |
|---|---|---|
| Named internal stage | Snowflake-managed storage; shareable, can have a file format | @landing |
| Table stage | One per table, automatic | @%orders |
| User stage | One per user, automatic | @~ |
| External stage | Your S3 bucket, Azure container or GCS bucket | @s3_landing (created with a URL + storage integration) |
Step 2: upload with PUT
We ran this with the Snowflake CLI (snow sql -f load.sql). PUT compresses each file with gzip and uploads them in parallel.
-- 3. Upload files from your laptop (Snowflake CLI or SnowSQL; Snowsight has an Upload button instead)
PUT file://~/shopkart/data/customers/customers.csv @landing/customers/ AUTO_COMPRESS = TRUE;
PUT file://~/shopkart/data/orders/orders_2026-1*.csv @landing/orders/ AUTO_COMPRESS = TRUE PARALLEL = 8;
PUT file://~/shopkart/data/products.csv @landing/products/;
LIST @landing/orders/ PATTERN = '.*orders_2026-10-0[1-3].*';| source | target | source_size | target_size | status |
|---|---|---|---|---|
| customers.csv | customers.csv.gz | 12313 | 2896 | UPLOADED |
| orders_2026-10-01.csv | orders_2026-10-01.csv.gz | 4548 | 1232 | UPLOADED |
| orders_2026-10-02.csv | orders_2026-10-02.csv.gz | 5402 | 1392 | UPLOADED |
| โฆ 59 more order files | UPLOADED |
| name | size | last_modified |
|---|---|---|
| landing/orders/orders_2026-10-01.csv.gz | 1232 | Sun, 22 Nov 2026 09:05:13 GMT |
| landing/orders/orders_2026-10-02.csv.gz | 1392 | Sun, 22 Nov 2026 09:05:13 GMT |
| landing/orders/orders_2026-10-03.csv.gz | 1136 | Sun, 22 Nov 2026 09:05:13 GMT |
Notice the compression: 12 KB of customers became under 3 KB.
Step 3: look before you load
You can query files sitting in a stage directly. $1, $2โฆ are the columns by position:
CREATE OR REPLACE TABLE orders (
order_id NUMBER(10,0),
customer_id NUMBER(10,0),
product_id NUMBER(10,0),
quantity NUMBER(5,0),
unit_price NUMBER(10,2),
status VARCHAR,
order_ts TIMESTAMP_NTZ
);
-- Peek inside a staged file before loading it: $1, $2... are the columns
SELECT $1 AS order_id, $2 AS customer_id, $6 AS status, METADATA$FILENAME AS file
FROM @landing/orders/orders_2026-10-01.csv.gz
LIMIT 3;| ORDER_ID | CUSTOMER_ID | STATUS | FILE |
|---|---|---|---|
| 100001 | 148 | PLACED | orders/orders_2026-10-01.csv.gz |
| 100002 | 31 | DELIVERED | orders/orders_2026-10-01.csv.gz |
| 100003 | 98 | DELIVERED | orders/orders_2026-10-01.csv.gz |
Step 4: COPY INTO
COPY INTO customers FROM @landing/customers/;| file | status | rows_parsed | rows_loaded | errors_seen |
|---|---|---|---|---|
| landing/customers/customers.csv.gz | LOADED | 200 | 200 | 0 |
200 rows, no errors. The stage already knows the file format, so we didn't repeat it. Now the orders, but carefully.
Dry run first
-- Dry run: check every orders file for problems, load nothing
COPY INTO orders FROM @landing/orders/ VALIDATION_MODE = RETURN_ERRORS;| ERROR | FILE | LINE | COLUMN_NAME | REJECTED_RECORD |
|---|---|---|---|---|
| Numeric value '100999x' is not recognized | orders/orders_2026-11-30.csv.gz | 101 | "ORDERS"["ORDER_ID":1] | 100999x,17,3,two,4999,DELIVERED,2026-11-30 10:15:00 |
| Numeric value 'two' is not recognized | orders/orders_2026-11-30.csv.gz | 101 | "ORDERS"["QUANTITY":4] | 100999x,17,3,two,4999,DELIVERED,2026-11-30 10:15:00 |
Found it: line 101 of the 30 November file has 100999x as an order ID and two as a quantity. Nothing was loaded. What happens if we load anyway?
-- The default is ON_ERROR = ABORT_STATEMENT: one bad row stops the whole load
COPY INTO orders FROM @landing/orders/;100038 (22018): Numeric value '100999x' is not recognized
File 'orders/orders_2026-11-30.csv.gz', line 101, character 1
Row 100, column "ORDERS"["ORDER_ID":1]
If you would like to continue loading when an error is encountered, use
other values such as 'SKIP_FILE' or 'CONTINUE' for the ON_ERROR option.One bad row out of 5,316 and the whole load stopped, with 0 rows in the table. That's the safe default (ON_ERROR = ABORT_STATEMENT). Here we decide the other 99 rows of that day are fine to load:
-- Load every good row, skip only the bad ones
COPY INTO orders FROM @landing/orders/ ON_ERROR = CONTINUE;| file | status | rows_parsed | rows_loaded | errors_seen | first_error |
|---|---|---|---|---|---|
| landing/orders/orders_2026-10-01.csv.gz | LOADED | 90 | 90 | 0 | |
| landing/orders/orders_2026-10-02.csv.gz | LOADED | 107 | 107 | 0 | |
| โฆ 58 more files | LOADED | 0 | |||
| landing/orders/orders_2026-11-30.csv.gz | PARTIALLY_LOADED | 100 | 99 | 1 | Numeric value '100999x' is not recognized |
| ON_ERROR | What happens |
|---|---|
| ABORT_STATEMENT (default) | Stop at the first error; load nothing |
| CONTINUE | Load good rows, skip bad rows |
| SKIP_FILE | Skip any file with an error (also SKIP_FILE_3 = skip if 3+ errors, SKIP_FILE_10% = skip if 10%+ bad) |
Re-running is safe
-- Run the very same COPY again
COPY INTO orders FROM @landing/orders/ ON_ERROR = CONTINUE;
SELECT COUNT(*) AS orders, MIN(order_ts)::DATE AS first_day, MAX(order_ts)::DATE AS last_day
FROM orders;| status |
|---|
| Copy executed with 0 files processed. |
| ORDERS | FIRST_DAY | LAST_DAY |
|---|---|---|
| 5315 | 2026-10-01 | 2026-11-30 |
Find bad loads later
-- Which files had problems? (last hour of loads into ORDERS)
SELECT file_name, status, row_count, error_count, first_error_message
FROM TABLE(information_schema.copy_history(
TABLE_NAME => 'SHOPKART.RAW.ORDERS',
START_TIME => DATEADD(hour, -1, CURRENT_TIMESTAMP())))
WHERE error_count > 0;| FILE_NAME | STATUS | ROW_COUNT | ERROR_COUNT | FIRST_ERROR_MESSAGE |
|---|---|---|---|---|
| orders/orders_2026-11-30.csv.gz | Partially loaded | 99 | 1 | Numeric value '100999x' is not recognized |
COPY_HISTORY covers the last 14 days (the SNOWFLAKE.ACCOUNT_USAGE.COPY_HISTORY view keeps a year). A good pipeline checks it after every load and alerts someone.
Transform while loading (a little)
COPY can pick, reorder and lightly clean columns with a SELECT. But not every function is allowed:
-- Clean while loading? Only some functions are allowed inside COPY
COPY INTO products (product_id, name, category, price)
FROM (SELECT $1, TRIM($2), UPPER($3), $4 FROM @landing/products/);002300 (0A000): SQL Compilation error: Function 'UPPER' not supported within a COPYTRUNCATE TABLE products;
-- Choose, reorder and lightly clean columns while loading
COPY INTO products (product_id, name, category, price)
FROM (SELECT $1, TRIM($2), $3, $4 FROM @landing/products/);
SELECT category, COUNT(*) AS products FROM products GROUP BY category ORDER BY category;| CATEGORY | PRODUCTS |
|---|---|
| Electronics | 4 |
| Fashion | 4 |
| Home | 4 |
Our first report
-- Our first real question: delivered revenue by city
SELECT c.city,
COUNT(*) AS orders,
SUM(o.quantity * o.unit_price) AS revenue
FROM orders o
JOIN customers c ON c.customer_id = o.customer_id
WHERE o.status = 'DELIVERED'
GROUP BY c.city
ORDER BY revenue DESC;| CITY | ORDERS | REVENUE |
|---|---|---|
| Delhi | 954 | 2200709.00 |
| Bengaluru | 889 | 2087701.00 |
| Mumbai | 832 | 1897466.00 |
| Kolkata | 775 | 1780712.00 |
| Pune | 695 | 1610135.00 |
Two months of ShopKart orders, loaded and answering a real question. In the next lesson the app also starts sending JSON events, and you'll learn how Snowflake handles data that doesn't fit neat columns.
Other ways to load
| Method | When to use it |
|---|---|
| COPY INTO (this lesson) | Batch loads on a schedule; most common |
| Snowpipe | Files arriving all day: loads each new file within about a minute (lesson 7) |
| Snowpipe Streaming | Rows from Kafka or apps, with seconds of delay, no files |
| Snowsight upload | One-off files with a few clicks (Ingestion โ Add data) |
| External / Iceberg tables | Query files in place without loading |
| Partner tools | Fivetran, Airbyte, Azure Data Factory, dbt and others |
๐ฏ Interview questions on this topic
Try to answer out loud first, then tap to check.
Q1How do you load a CSV file from your machine into Snowflake?Fresher+
Q2What's the difference between an internal and an external stage?Fresher+
Q3How does Snowflake avoid loading the same file twice?1โ3 yrs+
Q4A daily load has a few bad rows. How do you handle it?1โ3 yrs+
Q5What transformations can you do inside COPY INTO?1โ3 yrs+
Q6How would you size files and warehouses for a large bulk load?3+ yrs+
Key takeaways
- โStage โ COPY INTO is the core of loading in Snowflake.
- โAlways dry-run new sources, and decide ON_ERROR on purpose.
- โCOPY remembers loaded files, so retries don't duplicate data.
- โLoad raw, transform afterwards: that's ELT.
Frequently asked questions
What is a stage in Snowflake?
A place where files wait before you load them into a table (or after you unload them). An internal stage is storage managed by Snowflake; an external stage points to your own cloud storage, like an S3 bucket or Azure container.
Why didn't my second COPY INTO load anything?
Snowflake remembers which files it already loaded into each table for 64 days (load metadata), and skips them. That makes re-running a load safe. Use FORCE = TRUE only if you really want to load the same files again (you'll get duplicates).
Can I use PUT in Snowsight?
No. PUT uploads from your computer, so it runs in the Snowflake CLI, SnowSQL or a driver (Python, JDBC). In Snowsight, use the Upload button on a stage or Ingestion โ Add data to upload files with the mouse.
ON_ERROR: CONTINUE, SKIP_FILE or ABORT_STATEMENT?
ABORT_STATEMENT (the default for COPY) stops at the first bad row and loads nothing. CONTINUE loads good rows and skips bad ones. SKIP_FILE skips any file that has an error. For production, many teams use ABORT_STATEMENT or SKIP_FILE plus alerts, so bad data is never half-loaded silently.
How big should my files be?
Snowflake recommends files of roughly 100โ250 MB compressed for bulk loading. Many tiny files add overhead; one huge file can't be loaded in parallel. Split big exports and combine tiny ones.
๐ง Quick check: loading data
1. Which command uploads a file from your laptop to an internal stage?
2. VALIDATION_MODE = RETURN_ERRORS...
3. You run the same COPY twice. What happens the second time?
4. With ON_ERROR = CONTINUE and one bad row in a 100-row file, the file's status is...
5. What does $3 mean when you SELECT from a stage?
Checking your accessโฆ