Step 3. Stage the Data Files

Snowflake supports loading data from files that have been staged in either an internal (Snowflake) stage or external (AWS S3 or Microsoft Azure) stage. Loading from an external stage is convenient if you already store data files in these cloud storage services.

In this tutorial, we will upload (stage) the sample data files (downloaded in Prerequisites) to an internal table stage. The command used to stage files is PUT.

In this Topic:

Staging the Files

Execute PUT to upload local data files to the table stage provided for the emp_basic table you created. Note that the command is OS-specific because it references files in your local environment:

  • Linux or Mac OS

    PUT file:///tmp/employees0*.csv @sf_tuts.public.%emp_basic;
    
  • Windows

    PUT file://C:\temp\employees0*.csv @sf_tuts.public.%emp_basic;
    

Let’s take a closer look at the command:

  • file: specifies the full directory path and names of the files on your local machine to stage. Note that file system wildcards are allowed.
  • @<namespace>.%<table_name> indicates to use the stage for the specified table, in this case the emp_basic table.

The command returns the following response, showing the files that were staged:

+-----------------+--------------------+-------------+-------------+--------------------+--------------------+----------+---------+
| source          | target             | source_size | target_size | source_compression | target_compression | status   | message |
|-----------------+--------------------+-------------+-------------+--------------------+--------------------+----------+---------|
| employees01.csv | employees01.csv.gz |         360 |         287 | NONE               | GZIP               | UPLOADED |         |
| employees02.csv | employees02.csv.gz |         355 |         274 | NONE               | GZIP               | UPLOADED |         |
| employees03.csv | employees03.csv.gz |         397 |         295 | NONE               | GZIP               | UPLOADED |         |
| employees04.csv | employees04.csv.gz |         366 |         288 | NONE               | GZIP               | UPLOADED |         |
| employees05.csv | employees05.csv.gz |         394 |         299 | NONE               | GZIP               | UPLOADED |         |
+-----------------+--------------------+-------------+-------------+--------------------+--------------------+----------+---------+

Note that the PUT command compresses files by default using gzip, as indicated in the TARGET_COMPRESSION column.

Listing the Staged Files (Optional)

You can see the list of the files you successfully staged by executing a LIST command:

LIST @sf_tuts.public.%emp_basic;

+--------------------+------+----------------------------------+------------------------------+
| name               | size | md5                              | last_modified                |
|--------------------+------+----------------------------------+------------------------------|
| employees01.csv.gz |  288 | a851f2cc56138b0cd16cb603a97e74b1 | Tue, 9 Jan 2018 15:31:44 GMT |
| employees02.csv.gz |  288 | 125f5645ea500b0fde0cdd5f54029db9 | Tue, 9 Jan 2018 15:31:44 GMT |
| employees03.csv.gz |  304 | eafee33d3e62f079a054260503ddb921 | Tue, 9 Jan 2018 15:31:45 GMT |
| employees04.csv.gz |  304 | 9984ab077684fbcec93ae37479fa2f4d | Tue, 9 Jan 2018 15:31:44 GMT |
| employees05.csv.gz |  304 | 8ad4dc63a095332e158786cb6e8532d0 | Tue, 9 Jan 2018 15:31:44 GMT |
+--------------------+------+----------------------------------+------------------------------+

Next: Step 4. Copy Data into the Target Table