June 14, 2023

What Are Snowflake Stages?

By Ayush Singh

This blog was co-written by Ayush Kumar Singh and Mayank Singh

The Snowflake Data Cloud is a cloud-based data warehousing platform that allows businesses to store and query data for analytical purposes. In order to do this, Snowflake leverages several different stages, allowing businesses to move their data from one place to another.

In this blog, we will unwrap what Snowflake stages are, explore the different kinds of stages, and, ultimately, how to use them.

What are Snowflake Stages?

Snowflake Stages are locations where data files are stored (staged) for loading and unloading data. They are used to move data from one place to another, and the locations for the stages could be internal or external to the Snowflake environment.

Businesses can use a Snowflake stage to move their data from external data sources such as S3 buckets to internal Snowflake tables or vice-versa.

The Snowflake stage is used to manage the data during the loading process.

For example, businesses can employ Snowflake stages to create temporary tables to store data before it is loaded into the main table. This allows businesses to ensure their data is getting appropriately loaded into Snowflake without having to bother about any potential issues that may emerge during the loading process.

Additionally, Snowflake stages provide businesses with a secure environment to house their data. With encryption features readily available, organizations can enhance their data security and guard against unauthorized access effectively.

How to Create a Snowflake Stage

Creating a Snowflake stage is a simple process. Just the name of the stage, location of data, and security settings are needed to create a stage. 

To create a Snowflake stage using WebUI, log in to the Snowflake console, on the Stages tab, click the “Create Stage” button. The stage creation process will prompt the user to specify the stage name, location, and security settings. 

After the stage has been created, you can start moving data.

What Are the Different Types of Snowflake Stages?

Snowflake supports two different types of data stages: external stages and internal stages. An external stage is used to move data from external sources, such as S3 buckets, to internal Snowflake tables. On the other hand, an internal stage is used as an intermediate storage location for data files before they are loaded into a table or after they are unloaded from a table.

Snowflake stages also allow businesses to control the data transfer process and protect their data from unauthorized access.

External Snowflake Stages

An external stage allows the user to control the data transfer process and protect their data from unauthorized access.

Users can also store their data in a secure environment using the external stage. With the external stage, businesses can easily encrypt their data for added security and protect it from unauthorized access.

Here’s an example of how you could create an external stage in Snowflake for an S3 bucket:

3 lines of code

Here, “my_stage” is our external stage name. Url tells Snowflake the location of our data and the credentials are the security information required to access that data.

Internal Snowflake Stages

A Snowflake internal stage is a storage location within a Snowflake account that temporarily holds data files during certain operations, such as loading data into a table or unloading data from a table.

An internal stage is created and managed by Snowflake and is not accessible to the user directly. It is used as an intermediate storage location for data files before they are loaded into a table or after they are unloaded from a table.

One of the main advantages of using an internal stage is that it allows for efficient data loading and unloading operations. When loading data into a table, Snowflake can load multiple data files in parallel, which can significantly improve load performance. Similarly, when unloading data from a table Snowflake can write multiple data files in parallel, which can also improve performance.

Here’s an example of how you could create an internal stage in Snowflake:

Notice here we don’t need to specify any URL or credentials as the data is stored within Snowflake.

There are three types of internal stages in Snowflake:

  1. Named stage
  2. User stage
  3. Table stage

Accessing a Snowflake Stage

Once a Snowflake stage is created, users can access it via WebUi by logging in to the Snowflake console. On the Stages tab, users can view a list of all their stages and select the one they want to access. Once the stage is selected, users can view the details of the stage, like location, security settings, and data.

a screenshot of a Snowflake stage

Users can also access their Snowflake stages by using the Snowflake CLI. Users can use the “show stages” command to list all their stages and select the one they want to access.

Snowflake COPY INTO Stage Table

The Snowflake “COPY INTO” stage table is a command that allows users to load data from a stage(internal/external) into a table. This further allows users to control the data transfer process and protect their data from unauthorized access.

To use the Snowflake COPY INTO stage table, users need to create a stage table and then use the COPY INTO command to load the data into the table. The COPY INTO command allows users to specify the data source, target table, and data format. Once the data is loaded into the staging table, users can use the SELECT command to move the data from the staging table to the main Snowflake table.

Here is an example of how one can use COPY INTO command in Snowflake:

More lines of code

Best Practices for Managing Snowflake Stages

Some of the best practices to manage Snowflake stages are as follows:

  1. Create a stage for each external data source. This will ensure that users can easily access the external data and move it to the Snowflake table.
  2. Use the Snowflake table staging process. This process allows users to load data into a temporary table before loading it into the main Snowflake table. This allows businesses to ensure that their data is properly loaded without having to worry about any potential problems that may arise during the loading process.
  3. Leverage the Snowflake COPY INTO the stage table process. This process allows users to control the data transfer process and protect their data from unauthorized access.

What is the Difference Between Stages and Tables in Snowflake?

In Snowflake, a stage represents a named object that acts as a temporary holding area for data files being loaded into a Snowflake table. The data can be stored in either Snowflake internal storage or external storage services like Amazon S3 or Microsoft Azure. A stage provides a way to manage and control access to the data being loaded into Snowflake.

A table, on the other hand, is a permanent and organized collection of data within Snowflake. Data can be loaded into a Snowflake table from a stage, either in a single transaction or in multiple transactions. Once the data is loaded into a table, it can be queried, transformed, and manipulated like any other data stored in Snowflake.

In summary, a stage acts as a landing zone for data before it’s loaded into a Snowflake table, while a table is the permanent storage area for the data within Snowflake.

How to List Files in a Snowflake Stage?

In Snowflake, you can use the LIST command to list the files in a stage. Here’s an example:

A single line of code showing a Snowflake Stage example

This example will show all of the files present in “my_stage.” This will give an output as follows:

You can also use the LIST command with the PATTERN clause to filter the files based on a pattern. For example, to list only the CSV files in the stage, you could use the following command:

In this example, the PATTERN clause is used to filter the files based on the .csv file extension. The LIST command will only return information for files that match the pattern.

Conclusion

Snowflake stages are an important component of the Snowflake platform. It is used to move data from one place to another. In this blog post, we explored Snowflake stages, covering what it is, the different types of stages available, how to create and access them, best practices for managing them, and more.

Overall, the Snowflake stage can be used to move data from one place to another quickly and securely. Using the snowflake stage, users can control the data transfer process and protect their data from unauthorized access.

If you are looking for an efficient and secure way to move your data into Snowflake, then the Snowflake stage is a great option. With the Snowflake stage, you can easily move your data quickly and securely.

Data Coach is our premium analytics training program with one-on-one coaching from renowned experts.

Accelerate and automate your data projects with the phData Toolkit