7.stages in Snowflake
7.stages in Snowflake
7.stages in Snowflake
by
Veerendra
Agenda
• What is a Stage?
• Stage Types
• External Stages
• Internal Stages
• Data load from Stages
What is a Stage?
• A stage specifies where data files are stored (i.e. “staged”) so
that the data in the files can be loaded into a table.
1. User Stage
2. Table Stage
3. Named Internal Stage
User Stage (@~)
• A user stage is allocated to each user for storing files.
• To store files that are staged and managed by a single user but can be
loaded into multiple tables.
• User stages cannot be altered or dropped.
• This option is not appropriate if multiple users require access to the
files.
Table Stage (@%)
• A table stage is available for each table created in Snowflake.
• Table stages have the same name as the table.
e.g. a table named mytable has a stage referenced as @%mytable
• To store files that are staged and managed by one or more users but
only loaded into a single table.
• Table stages cannot be altered or dropped.
• Note that a table stage is not a separate database object, rather it is
an implicit stage tied to the table itself.
Named Internal Stage (@)
• A named internal stage is a database object created in a schema
• To store files that are staged and managed by one or more users and
loaded into one or more tables.
• Create stages using the CREATE STAGE command (similar to external
stages)
Linux or macOS:
put file:///data/data.csv @~/staged;
put file:///data/data.csv @%mytable; Listing Files:
put file:///data/data.csv @my_stage; list @~;
list @%mytable;
list @my_stage;
Windows:
put file://c:\data\data.csv @~/staged;
put file://c:\data\data.csv @%mytable;
put file://c:\data\data.csv @my_stage;
Copying data from Internal stage
User Stage:
To Load all files prefixed with staged in your user stage,
copy into mytable from @~/staged
file_format = (type = csv field_delimiter = '|' skip_header = 1);
Table Stage:
To load all files in the stage for the customer table,
copy into mytable from @%customer
file_format = (format_name = my_csv_format);
Copying data from Internal stage
Named Stage:
To load all files from the my_stage named stage,
copy into mytable from @my_stage;