What is Stage in Snowflake: Definition and Usage
stage is a location where data files are stored temporarily before loading into or unloading from tables. It acts like a holding area for files, either inside Snowflake or in external cloud storage, to simplify data transfer operations.How It Works
Think of a stage in Snowflake as a mailbox where you drop off or pick up packages (data files). Instead of sending data directly into a table, you first place it in this mailbox. This makes managing data easier and more organized.
Stages can be internal, meaning Snowflake manages the storage, or external, where files live in cloud storage services like Amazon S3, Microsoft Azure Blob Storage, or Google Cloud Storage. When you want to load data into Snowflake tables, you tell Snowflake to look in the stage and bring the files in. When exporting data, Snowflake puts the files into the stage for you to retrieve.
Example
This example shows how to create an internal stage, upload a file, and load data into a table.
CREATE OR REPLACE TABLE employees (id INT, name STRING); CREATE OR REPLACE STAGE my_stage; -- Upload a CSV file named 'employees.csv' to the stage (done via Snowflake UI or CLI tool) COPY INTO employees FROM @my_stage/employees.csv FILE_FORMAT = (TYPE = 'CSV' FIELD_DELIMITER = ',' SKIP_HEADER = 1);
When to Use
Use stages when you need to move data files into or out of Snowflake efficiently. For example, if you receive daily sales data files, upload them to a stage first, then load them into tables. This approach helps separate file management from data processing.
Stages are also useful when exporting data for backup or sharing. You can unload table data into a stage, then download or transfer files from there.
Key Points
- A stage is a temporary storage area for data files in Snowflake.
- Stages can be internal (managed by Snowflake) or external (cloud storage).
- They simplify loading and unloading data by acting as a file holding place.
- Using stages helps organize data workflows and improves efficiency.
