How to Use PUT Command in Snowflake: Syntax and Examples
Use the
PUT command in Snowflake to upload local files to a Snowflake stage for loading data. The command syntax is PUT 'file_path' @stage_name; where file_path is your local file and @stage_name is the target stage.Syntax
The PUT command uploads files from your local machine to a Snowflake stage. It requires the local file path and the target stage name. Optional parameters control file overwriting and parallelism.
- file_path: Path to the local file or files (supports wildcards).
- @stage_name: The Snowflake stage where files will be uploaded.
- OVERWRITE: Optional keyword to replace existing files with the same name.
- PARALLEL: Optional number to specify parallel upload threads.
sql
PUT 'file:///path/to/file.csv' @my_stage OVERWRITE = TRUE PARALLEL = 4;
Example
This example uploads a local CSV file named data.csv from your computer to a Snowflake user stage called @my_stage. It overwrites any existing file with the same name and uses 2 parallel threads for faster upload.
sql
PUT 'file:///home/user/data.csv' @my_stage OVERWRITE = TRUE PARALLEL = 2;
Output
File 'data.csv' uploaded successfully to @my_stage.
Common Pitfalls
Common mistakes when using PUT include:
- Not using the
file://prefix for local file paths. - Trying to upload files without specifying a stage.
- Forgetting to set
OVERWRITE = TRUEwhen you want to replace existing files. - Using incorrect file paths or missing file permissions.
Always verify your local file path and stage name before running the command.
sql
/* Wrong: Missing file:// prefix */ PUT '/home/user/data.csv' @my_stage; /* Right: Correct file path with prefix */ PUT 'file:///home/user/data.csv' @my_stage;
Quick Reference
| Parameter | Description | Example |
|---|---|---|
| file_path | Local file path with file:// prefix | 'file:///path/to/file.csv' |
| @stage_name | Target Snowflake stage | @my_stage |
| OVERWRITE | Replace existing files (TRUE/FALSE) | OVERWRITE = TRUE |
| PARALLEL | Number of parallel upload threads | PARALLEL = 4 |
Key Takeaways
The PUT command uploads local files to a Snowflake stage using the syntax: PUT 'file_path' @stage_name;
Always include the 'file://' prefix in local file paths for the PUT command.
Use OVERWRITE = TRUE to replace files with the same name in the stage.
Specify PARALLEL to speed up uploads with multiple threads.
Verify file paths and stage names to avoid upload errors.
