In Snowflake, we can upload CSV(Comma-Separated Values) files from the local machines that are available on macOS, Windows, and Linux operating systems. In this blog, we will discuss the process of importing the CSV files.
Snowflake lets us upload the CSV file from our local machines that run on Linux, macOS, or Windows. In the following example, the file we import is known as “Organizations.” It will have three columns(O.id, O.location, and O.name), is located in the ‘test1’ folder of the local machine, and contains the below structure:
Step1:
Create the Snowflake stage.
Create or replace stage organizations_stage1;
Step2:
Create the file format through “FILE FORMAT” command for explaining the format of the file we import:
create or replace file format organizations_format type = ‘CSV’ field delimiter = ‘,’;
Step3:
Upload our CSV file from the local folder to the Snowflake stage through “PUT” command:
Linux/Mac:
put file:///tmp1/data1/Oragnizations.csv @organizations_stage1;
Windows:
put file://D: \test1\Organizations.CSV @organizations_stage1;
Step4:
Check to view if Snowflake stage is inhabited with data from file.
Select
b.$1,
b.$2,
b.$3
from @_stage1 (file_format => organizations_format1) c;
Step5:
We have to create the table in the Snowflake database that contains a similar structure to the CSV file we have to import before running “COPY INTO” command.
Create or replace table organizations (
O.Id integer,
O.name varchar(100),
O.location varchar(100)
)
Step6:
Load the data from the Snowflake stage into the Snowflake database table through the “COPY INTO” command
copy into test.organizations from @organizations_stage1;
copy into test.organizations from (select c.$1, c.$2, from @organizations_stage1 (file_format1 => organizations_format1) c);
Step7:
Check to view if Snowflake database table is inhabited with data
select * from organizations;
O.id | O.name | O.locatio |
101 | Canada | |
102 | Amazon | Washington |
103 | Flipkart | California |
This blog includes all the steps required for importing the CSV(Comma Separated Values) files into the Snowflake. It also tells you how to get the output in the required format. I hope this is sufficient for working with the CSV files in Snowflake.
Snowflake Related Articles
If you have any queries, let us know by commenting below.
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Snowflake Training | Nov 19 to Dec 04 | View Details |
Snowflake Training | Nov 23 to Dec 08 | View Details |
Snowflake Training | Nov 26 to Dec 11 | View Details |
Snowflake Training | Nov 30 to Dec 15 | View Details |