3: Data Loading and Virtual Warehouses

    Working with Structured and Semi-Structured Data Using Stages

    What a stage actually is

    A stage in Snowflake is a named pointer to a directory of files.

    Those files can sit in storage that Snowflake manages on the customer's behalf (an internal stage) or in a cloud-storage bucket the customer already operates (an external stage).

    The stage object itself is metadata in the database catalog. It records the URL, an optional file format, an optional encryption key, an optional storage integration, and an optional directory setting. The actual bytes never live in the catalog; the stage is just the address.

    How it works

    This separation between catalog metadata and storage bytes is what allows the four stage families to coexist with the same syntax. A query that references @SALES.PUBLIC.RAW_FILES and a query that references @~ and a query that references @%CUSTOMERS all resolve through the same lookup machinery. The only difference is where the bytes physically sit and which role can read or write them.

    Stages are also the only object type in Snowflake that holds files. Tables hold rows; views hold a query definition; stages hold opaque files.

    Every bulk data path into Snowflake goes through a stage first, even when the user does not notice. A COPY INTO statement that points at a direct S3 URL still creates a transient external-stage object behind the scenes. A Snowsight upload still writes to a stage. Working knowledge of the four stage families is the entry point for every ingestion task the exam puts in front of a candidate.

    Named internal stages

    A named internal stage is a stage object the customer creates and grants like any other database object. The bytes live in Snowflake-managed object storage, encrypted with a Snowflake-managed key by default. The object lives inside a database and schema, has a fully qualified name, and supports the standard CREATE / ALTER / DROP / GRANT lifecycle.

    USE ROLE SYSADMIN;
    USE DATABASE SALES;
    USE SCHEMA PUBLIC;
    
    CREATE OR REPLACE STAGE RAW_FILES
     FILE_FORMAT = (TYPE = CSV FIELD_DELIMITER = '|' SKIP_HEADER = 1)
     COMMENT = 'Pipe-delimited daily extracts from the order system';
    
    GRANT USAGE ON STAGE SALES.PUBLIC.RAW_FILES TO ROLE LOADER;
    GRANT READ ON STAGE SALES.PUBLIC.RAW_FILES TO ROLE LOADER;
    GRANT WRITE ON STAGE SALES.PUBLIC.RAW_FILES TO ROLE LOADER;
    

    Files reach a named internal stage through the SnowSQL PUT command, through Snowsight uploads, or through Snowpark file-IO calls.

    Once on the stage, those files can be read with LIST, queried directly with the @stage syntax, or loaded into a table with COPY INTO.

    Named internal stages are the right answer when a team wants a reusable shared landing zone with explicit access control and a stable name to script against.

    💡 Exam Trap: A named internal stage requires both USAGE on the stage object and READ (for reads) or WRITE (for writes) on its files. Granting USAGE alone lets a role see the stage in catalog views but not list or download its contents. Distractor answers that grant only USAGE and expect file access are wrong by design.

    Named external stages

    A named external stage is a catalog object that points at an external cloud-storage URL:

    • an S3 bucket
    • an Azure Blob container
    • a Google Cloud Storage bucket

    Snowflake never copies those files into its own storage tier until COPY INTO or a similar load command actually reads them and writes rows into a table.

    Until then, the bytes stay where they are and the customer pays only their existing cloud-storage costs.

    CREATE OR REPLACE STAGE SALES.PUBLIC.S3_LANDING
     URL = 's3://orders-landing/prod/'
     STORAGE_INTEGRATION = AWS_LANDING_INT
     FILE_FORMAT = (TYPE = PARQUET);
    

    External stages bind to a STORAGE_INTEGRATION object that holds the cloud IAM trust relationship.

    That integration is the production-grade alternative to embedding access keys directly in the stage definition. A candidate should recognize the pattern:

    • the integration is created once at the account level by ACCOUNTADMIN,
    • granted to roles,
    • and then referenced by every external stage that targets that cloud account.

    User stages

    Every Snowflake user automatically has a private user stage referenced by the symbol @~.

    The user owns it, it lives outside any database or schema, and no other user can read or write it. Nothing creates it; nothing drops it; it shares the user's lifecycle. It cannot be granted to other roles, period.

    A common confusion on the exam is whether USAGE on someone else's user stage is possible; it is not.

    In practice

    User stages are convenient for ad-hoc work:

    • a data analyst uploads a one-off CSV to @~
    • runs COPY INTO from there into a sandbox table
    • and walks away

    Because the stage is invisible to other users, it is a poor choice for shared ingestion pipelines or anything that has to survive an employee leaving the company.

    Table stages

    Every permanent or transient table in Snowflake also has an automatic table stage. The reference syntax is @%TABLE_NAME.

    Like user stages, the table stage cannot be created, dropped, or granted on its own; it inherits the table's lifecycle and access permissions. Anyone with privileges on the table has matching privileges on its stage.

    • Table stages have a single intended use: they hold files destined for exactly that one table.
    • They cannot define a custom file format separate from the COPY INTO command.
    • They cannot be referenced as the source for loading a different table.
    • They are an attractive landing place when ingestion is one-to-one with the target and there is no reason to model a shared stage.

    📊 Limit: A user stage and a table stage cannot have their file format altered, because they have no DDL surface to alter. The file format has to be specified inline on COPY INTO or referenced as a named file format object passed at load time.

    Stage reference syntax at a glance

    Stage familyReferenceCreated byGrantableTypical use
    Named internal@DB.SCHEMA.STAGECREATE STAGEYesShared landing zone managed in Snowflake storage
    Named external@DB.SCHEMA.STAGECREATE STAGE … URL =YesFiles stay in S3, Azure Blob, or GCS
    User@~Implicit, per userNoPer-user scratch space
    Table@%TABLE_NAMEImplicit, per tableNo (inherits)Files loaded into exactly one table

    Working with unstructured data using Directory Tables

    A Directory Table is a managed read-only catalog of the files on a stage.

    Once enabled, every file on the stage gets a row in the Directory Table the next time metadata refreshes.

    Each row carries the file's relative path, size, last-modified timestamp, MD5 checksum, ETag, and a FILE_URL that points at the file.

    The Directory Table is the SQL surface that turns "a folder of PDFs" into "a queryable inventory of PDFs".

    CREATE OR REPLACE STAGE SALES.PUBLIC.DOCS
     URL = 's3://customer-docs/inbox/'
     STORAGE_INTEGRATION = AWS_LANDING_INT
     DIRECTORY = (ENABLE = TRUE AUTO_REFRESH = TRUE);
    
    ALTER STAGE SALES.PUBLIC.DOCS REFRESH;
    
    SELECT RELATIVE_PATH, SIZE, LAST_MODIFIED, FILE_URL
    FROM DIRECTORY(@SALES.PUBLIC.DOCS)
    WHERE RELATIVE_PATH LIKE '%.pdf'
    ORDER BY LAST_MODIFIED DESC;
    

    Directory Tables are how unstructured data gets joined to structured records.

    A claims table can carry a CLAIM_ID column and a DOC_PATH column. The Directory Table over the stage of claim documents has matching RELATIVE_PATH values. Joining the two surfaces every claim alongside its supporting PDF without ever copying the files into a Snowflake table. The Directory Table is metadata only; it never holds file contents.

    The AUTO_REFRESH flag wires the stage into cloud-native notifications (an SQS queue for S3, an Event Grid topic for Azure, a Pub/Sub topic for GCS). When a new file appears, the cloud emits an event and Snowflake re-reads the metadata. Without auto-refresh, the customer has to call ALTER STAGE … REFRESH manually before new files show up.

    ⚠️ Anti-Pattern: Treating a Directory Table like a normal table and trying to INSERT or UPDATE rows. The Directory Table is a managed view over the stage. The only write path is uploading or deleting files on the underlying storage. Attempts to write through SQL return an error.

    💡 Exam Trap: A stage created without DIRECTORY = (ENABLE = TRUE) cannot be queried with DIRECTORY(@stage). Enabling directory after the fact requires ALTER STAGE … SET DIRECTORY = (ENABLE = TRUE) followed by a manual REFRESH for the catalog to populate. Forgetting the REFRESH step is the most common reason a query returns zero rows on a freshly enabled directory.

    🎯 Scenario: A customer-support team lands signed contracts as PDFs into an S3 bucket every night. A loader team writes the contract metadata to a CONTRACTS table. The auditors need to know, at any point in time, that every contract row has a matching PDF and every PDF has a matching row. Enabling a Directory Table on the named external stage that points at the bucket gives them a SQL join between the CONTRACTS.FILE_NAME column and the Directory Table's RELATIVE_PATH, with LAST_MODIFIED available for delta-style audits.

    Decision Anchor. Choose a named internal stage when ingestion is shared across roles, files should live in Snowflake-managed storage, and the team needs a stable grant surface. Choose a named external stage when files already exist in S3, Azure Blob, or GCS and copying them into Snowflake-managed storage adds cost without benefit.

    Choose @~ for one-off personal uploads that no one else needs to read. Choose @%TABLE when the target is exactly one table and a separate stage would only add catalog clutter.


    Continue with the interactive course

    Track your progress, jump into practice questions and use the Shark AI tutor inside the Snowflake - SnowPro Associate Platform learning hub.