Efficient Data Loading with COPY INTO
Overview
COPY INTO is a bulk loading command in Snowflake used to load data on demand from external storage like Amazon S3 into Snowflake tables. Unlike Snowpipe (which provides continuous auto-ingestion), COPY INTO is manual or scheduled but gives more control, better error handling, and batch loading performance.
When to Use COPY INTO
| Use Case | Choose COPY INTO |
|---|---|
| One-time or periodic batch loads | Yes |
| Scheduled ETL/ELT jobs | Yes |
| Need more control over loading | Yes |
| Continuous streaming-like ingestion | Use Snowpipe instead |
Prerequisites
Before you start, ensure:
- Snowflake account is set up
- Warehouse and database exist
- IAM role for S3 access configured
- Data files prepared (CSV, JSON, Parquet etc.)
Steps
Step 1: Create Warehouse, Database, and Schema
CREATE WAREHOUSE IF NOT EXISTS COPY_WH WAREHOUSE_SIZE = 'XSMALL'
CREATE DATABASE IF NOT EXISTS COPY_DB;
CREATE SCHEMA IF NOT EXISTS COPY_SCHEMA;
Step 2: Create Target Table
CREATE OR REPLACE TABLE CUSTOMER_DATA (
CUSTOMER_ID INT,
FIRST_NAME STRING,
LAST_NAME STRING,
EMAIL STRING,
COUNTRY STRING,
CREATED_AT TIMESTAMP
);
Step 3: Configure AWS S3 External Stage
Option A: Using AWS Access Key
CREATE OR REPLACE STAGE CUSTOMER_S3_STAGE
URL='s3://my-bucket/customer-data/'
CREDENTIALS = (AWS_KEY_ID='YOUR_AWS_KEY' AWS_SECRET_KEY='YOUR_AWS_SECRET');
Option B: Using AWS IAM Role
CREATE OR REPLACE STAGE CUSTOMER_S3_STAGE
URL='s3://my-bucket/customer-data/'
CREDENTIALS = (AWS_ROLE='arn:aws:iam::123456789012:role/mySnowflakeRole');