Directory Tables are a Snowflake feature that lets you query file metadata (path, size, last-modified time, checksum, and more) on stages using SQL. They integrate data lake file management into Snowflake SQL operations, enabling file listing, diff detection, and Stream-driven file arrival event processing.
-- Enable Directory Tables on an existing stage
ALTER STAGE raw_data_stage SET DIRECTORY = (ENABLE = TRUE);
-- Enable when creating a new stage (External Stage / S3 example)
CREATE OR REPLACE STAGE landing_stage
URL = 's3://my-bucket/landing/'
STORAGE_INTEGRATION = s3_integration
DIRECTORY = (ENABLE = TRUE);
-- Enable auto-refresh at the same time
CREATE OR REPLACE STAGE landing_stage
URL = 's3://my-bucket/landing/'
STORAGE_INTEGRATION = s3_integration
DIRECTORY = (
ENABLE = TRUE
AUTO_REFRESH = TRUE
);
-- Internal Stage example
CREATE OR REPLACE STAGE internal_landing
DIRECTORY = (ENABLE = TRUE);| Column | Type | Description |
|---|---|---|
| RELATIVE_PATH | VARCHAR | Relative file path from the stage root |
| SIZE | NUMBER | File size in bytes |
| LAST_MODIFIED | TIMESTAMP_LTZ | File last-modified timestamp |
| MD5 | VARCHAR | MD5 hash of the file (External Stage only) |
| ETAG | VARCHAR | Cloud storage ETag |
| FILE_URL | VARCHAR | URL used to access the file from within Snowflake |
-- List all files in the stage
SELECT * FROM DIRECTORY(@landing_stage);
-- Filter by file extension
SELECT relative_path, size, last_modified
FROM DIRECTORY(@landing_stage)
WHERE relative_path LIKE '%.parquet';
-- Files added in the last 24 hours
SELECT relative_path, size, last_modified
FROM DIRECTORY(@landing_stage)
WHERE last_modified >= DATEADD(HOUR, -24, CURRENT_TIMESTAMP());
-- Aggregate file count and size
SELECT
SPLIT_PART(relative_path, '.', -1) AS file_extension,
COUNT(*) AS file_count,
SUM(size) / (1024 * 1024) AS total_size_mb
FROM DIRECTORY(@landing_stage)
GROUP BY file_extension
ORDER BY total_size_mb DESC;-- Refresh metadata for the whole stage
ALTER STAGE landing_stage REFRESH;
-- Refresh only a specific subpath (efficient for many files)
ALTER STAGE landing_stage REFRESH SUBPATH = '/2026/03/';When auto-refresh (AUTO_REFRESH = TRUE) is enabled, metadata is updated automatically using cloud storage event notifications as the trigger. Auto-refresh is not available on Internal Stages, so manual refresh is required there.
| Cloud | Event Notification | Setup Steps |
|---|---|---|
| AWS S3 | SNS topic + S3 event notification | Get the policy with SYSTEM$GET_AWS_SNS_IAM_POLICY() and apply it to SNS |
| Azure Blob | Event Grid | Generate a SAS token with SYSTEM$GET_AZURE_SAS_TOKEN() and configure Event Grid |
| GCS | Pub/Sub notification | Get the service account with SYSTEM$GET_GCP_SERVICE_ACCOUNT() and configure it on Pub/Sub |
-- Create a Stream on a Directory Table
CREATE OR REPLACE STREAM landing_file_stream
ON STAGE landing_stage;
-- Detect newly arrived files via the Stream
SELECT *
FROM landing_file_stream
WHERE METADATA$ACTION = 'INSERT';
-- Use a Task to auto-process new files
CREATE OR REPLACE TASK process_new_files
WAREHOUSE = etl_wh
SCHEDULE = '5 MINUTE'
WHEN SYSTEM$STREAM_HAS_DATA('landing_file_stream')
AS
COPY INTO raw_data
FROM @landing_stage
FILES = (
SELECT RELATIVE_PATH
FROM landing_file_stream
WHERE METADATA$ACTION = 'INSERT'
)
FILE_FORMAT = (TYPE = 'PARQUET');-- Scoped URL (temporary URL valid within the session)
SELECT BUILD_SCOPED_FILE_URL(@landing_stage, relative_path)
FROM DIRECTORY(@landing_stage)
WHERE relative_path LIKE '%.pdf';
-- Stage URL (for internal Snowflake references)
SELECT BUILD_STAGE_FILE_URL(@landing_stage, relative_path)
FROM DIRECTORY(@landing_stage);
-- Presigned URL (for external sharing, with expiration)
SELECT GET_PRESIGNED_URL(@landing_stage, relative_path, 3600)
FROM DIRECTORY(@landing_stage)
WHERE relative_path = 'reports/2026-Q1.pdf';-- Estimate auto-refresh cost
SELECT SYSTEM$ESTIMATE_AUTOMATIC_REFRESH_COST('landing_stage');Data Loading
問題 1
You enabled Directory Tables with AUTO_REFRESH = TRUE on an External Stage backed by S3. New files have been uploaded to S3 but they are not appearing in the DIRECTORY() function results. What is the most likely cause?
正解: B
Auto-refresh for Directory Tables on S3 requires a notification pipeline: S3 bucket event notifications → SNS topic → Snowflake. If this configuration is incomplete, file-addition events never reach Snowflake and metadata is not auto-updated. Directory Tables work on both External and Internal Stages and are available even on Standard Edition.
Do Directory Tables auto-refresh operations consume credits?
Yes. Auto-refresh is a serverless process that updates metadata in response to event notifications (AWS SNS / Azure Event Grid / GCP Pub/Sub) and is billed as Serverless Credits. Costs grow on stages with frequent file additions and deletions, so it is recommended to estimate costs ahead of time using the SYSTEM$ESTIMATE_AUTOMATIC_REFRESH_COST() function.
Can you add custom columns to Directory Tables metadata?
You cannot add custom columns to Directory Tables themselves. Only the fixed columns (RELATIVE_PATH, SIZE, LAST_MODIFIED, MD5, ETAG, FILE_URL) are provided. When custom attributes are required, a common pattern is to JOIN the Directory Tables result with an external metadata management table.
Can Directory Tables be used with both Internal and External Stages?
Yes, Directory Tables can be enabled on both stage types. However, auto-refresh is only supported on External Stages (S3 / GCS / Azure Blob). For Internal Stages, you must manually run ALTER STAGE REFRESH to update metadata.
Practice with certification-focused question sets
無料で問題を解いてみるNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Snowflake Certifications: All 11 Exams Explained (2026)
Every SnowPro certification — Associate, Core, Specialty, Ad...
Snowflake Exam Difficulty Ranking: All 11 Certs Compared (2026)
All 11 SnowPro exams ranked by difficulty with study-time es...
Snowflake Study Guide: Fastest Pass Route by Exam (2026)
How to pass SnowPro certifications efficiently — official ma...
SnowPro Core (COF-C03): Complete Exam Guide (2026)
Pass the SnowPro Core exam — six domains, scope, sample ques...
SnowPro Associate Platform (SOL-C01): Complete Guide (2026)
The entry-level SnowPro Associate exam — scope, weighting, s...