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 withgcs://.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_INTEGRATIONproperly, which leads to authentication errors. - Using an incorrect
URLformat; it must start withgcs://and include the bucket name. - Omitting the
FILE_FORMATwhen 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
| Parameter | Description | Example |
|---|---|---|
| stage_name | Name of the stage in Snowflake | my_gcs_stage |
| URL | GCS bucket path starting with gcs:// | gcs://my-bucket/path/ |
| STORAGE_INTEGRATION | Authentication integration for GCS | gcs_integration |
| FILE_FORMAT | Defines 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.
