Bird
Raised Fist0
SnowflakeHow-ToBeginner · 3 min read

How to Create a Stage for Google Cloud Storage in Snowflake

To create a stage for Google Cloud Storage (GCS) in Snowflake, use the CREATE STAGE command with the URL pointing to your GCS bucket and specify the STORAGE_INTEGRATION for authentication. This setup allows Snowflake to securely access your GCS data for loading or unloading.
📐

Syntax

The CREATE STAGE command defines a named location in Google Cloud Storage for Snowflake to read from or write to. Key parts include:

  • stage_name: The name you assign to the stage.
  • URL: The full path to your GCS bucket, starting with gcs://.
  • STORAGE_INTEGRATION: The Snowflake integration object that manages secure authentication to GCS.
  • FILE_FORMAT: Optional, defines the format of files in the stage.
sql
CREATE STAGE stage_name
  URL='gcs://your-bucket-name/path/'
  STORAGE_INTEGRATION = integration_name
  FILE_FORMAT = (type = 'file_format_type');
💻

Example

This example creates a stage named my_gcs_stage that points to a GCS bucket my-snowflake-bucket using a storage integration called gcs_integration. It also sets the file format to CSV.

sql
CREATE STAGE my_gcs_stage
  URL='gcs://my-snowflake-bucket/data/'
  STORAGE_INTEGRATION = gcs_integration
  FILE_FORMAT = (type = 'CSV' field_delimiter = ',' skip_header = 1);
Output
Stage MY_GCS_STAGE created.
⚠️

Common Pitfalls

Common mistakes when creating a GCS stage in Snowflake include:

  • Not creating or configuring the STORAGE_INTEGRATION properly, which leads to authentication errors.
  • Using an incorrect URL format; it must start with gcs:// and include the bucket name.
  • Omitting the FILE_FORMAT when your files are not in the default format, causing load failures.
sql
/* Wrong: Missing STORAGE_INTEGRATION */
CREATE STAGE bad_stage
  URL='gcs://my-bucket/data/';

/* Right: Include STORAGE_INTEGRATION */
CREATE STAGE good_stage
  URL='gcs://my-bucket/data/'
  STORAGE_INTEGRATION = gcs_integration;
📊

Quick Reference

ParameterDescriptionExample
stage_nameName of the stage in Snowflakemy_gcs_stage
URLGCS bucket path starting with gcs://gcs://my-bucket/path/
STORAGE_INTEGRATIONAuthentication integration for GCSgcs_integration
FILE_FORMATDefines file type and options(type='CSV' field_delimiter=',' skip_header=1)
✅

Key Takeaways

Always specify STORAGE_INTEGRATION to securely connect Snowflake with GCS.
Use the correct URL format starting with gcs:// followed by your bucket name.
Define FILE_FORMAT if your files are not in Snowflake's default format.
Test your stage by listing files or loading data to confirm correct setup.
Proper permissions on GCS and Snowflake integration are essential for access.